This is my code
private Rigidbody rb;
void start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical );
rb.AddForce (movement);
}
}
Why do I get a error code that says:
NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.FixedUpdate () (at Assets/PLayerMovement.cs:20)
I would like to know 2 things:
- Why did I get this error?
- How do I fix this error
Additional Info:
I am a beginner and am learning unity through the video tutorials. This was the roll a ball tutorial. If possible, please copy this code, fix it, and post it in the answers and explain what happened in simple language.
Many Thanks ![]()