ERROR - An object reference is required to access non-static member

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class Rocket : MonoBehaviour {

    Rigidbody rb;

	// Use this for initialization
	void Start () {
        rb = GetComponent<Rigidbody>();
	}
	
	// Update is called once per frame
	void Update ()
    {
        ProcessInput();
    }

    private static void ProcessInput()
    {
        if(Input.GetKey(KeyCode.Space))
        {
            rb.AddRelativeForce(Vector3.up);
        }
        if(Input.GetKey(KeyCode.LeftArrow))
        {
            print("Left Rotate");
        }
        else if(Input.GetKey(KeyCode.RightArrow))
        {
            print("Right Rotate");
        }
    }


}

Im getting ,An object reference is required to access non-static member, as an error. I refered rb to Rigidbody but the program does not notice it.

Hi Roman,

The problem is that your method definition for ProcessInput is static, remove the static keyword and this issue should be resolved.


See also;

Privacy & Terms