CS0120: An object reference is required for the non-static field, method, or property 'PlayerControls.currentState' code example

Example 1: CS0120: An object reference is required for the non-static field, method, or property 'PlayerControls.currentState'

PlayerController obj = new PlayerController();
 void OnTriggerEnter2D(Collider2D collider) {
     if (collider.tag == "Player")
     {
         Debug.Log("Player is Re-Fueling"); 
         obj.AddFuel(1);
     }

Example 2: CS0120: An object reference is required for the non-static field, method, or property 'PlayerControls.currentState'

public class Upgrader1 : MonoBehaviour
{

PlayerController PlayerController; //It should be member variable

void Start()
{
    GameObject Player = GameObject.Find("Player");
    PlayerController = Player.GetComponent();
}

public void Upgrade1()
{
    PlayerController.speed++;
}
}

Tags:

Misc Example