Well I tried to research this issue to see how common it is and I’ve found a lot of errors mentioned that I don’t seem to have. That being said, I can’t find any errors elsewhere and I’m wondering if a second pair of eyes might help?
I am using C#, and the problem seems to come from line 24 based on the error I receive. I tried a couple different things as well, such as changing the command to rb.velocity, but it would not work because it can apparently not be used as a method.
Error:
NullReferenceException: Object
reference not set to an instance of an
object PlayerControls.FixedUpdate ()
(at
Assets/Scripts/PlayerControls.cs:24)
Code:
using UnityEngine;
using System.Collections;
public class PlayerControls : MonoBehaviour
{
//Public or Private Declarations
public float speed = 100.0f;
private Rigidbody rb;
//initialization of movement
void start()
{
rb = GetComponent<Rigidbody>();
}
//application to each frame of movement
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal"); //x variable
float moveVertical = Input.GetAxis("Vertical"); //z variable
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}//end FixedUpdate
}//end Startusing UnityEngine;