error CS0103: The name does not exist in the current context

ConsoleCompiler error · Compiler

error CS0103: The name 'X' does not exist in the current context

You used a name, usually a variable, that is not declared where the code can see it. C# looks for names in the current block, then the method, then the class.

Read the Console line first

X is the name C# could not find. The file and line come before the message.

Common causes

  1. The variable was declared inside another block

    A variable declared inside an if, a loop or another method does not exist outside it. Declare it at class level to share it between methods.

  2. The name is misspelled

    moveSpeed and movespeed are different names.

  3. A static helper is called without its class

    Mathf.Clamp, not Clamp, unless you add using static UnityEngine.Mathf;.

The fix

Fix
C#
public class Jumper : MonoBehaviour
{
    private bool isGrounded; // class level: visible to every method

    void Update()
    {
        if (isGrounded && Input.GetButtonDown("Jump")) Jump();
    }
}

Stop it coming back

Keep fields at the top of the class and give locals short, obvious scopes.

Questions

I declared the variable in Start. Why can't Update see it?
A variable declared inside a method only exists inside that method. Declare it as a field in the class body, outside every method, and assign it in Start; then every method in the class can use it.
Why does Instantiate or Destroy not exist in my class?
Those methods belong to UnityEngine.Object, which MonoBehaviour inherits from. In a plain C# class, call them through the class: Object.Instantiate(prefab) and Object.Destroy(obj), with using UnityEngine; at the top.
Is C# case-sensitive?
Yes. playerHealth and PlayerHealth are different names. Unity's own APIs use PascalCase for methods and properties, such as transform.position and Time.deltaTime.

Related errors

Got a different error? Paste it into the error lookup.