- Home /
first time coding, getting "NullReferenceException: Object reference not set to an instance of an object" error
making the beginner rollaball game from the tutorials and I copied the code exactly as they show it and I keep getting this error NullReferenceException: Object reference not set to an instance of an object
heres the code
using UnityEngine;
using System.Collections;
public class playercontroller : MonoBehaviour {
public float speed;
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);
}
just trying to get the ball to move, its saying the "rb.AddForce (movement);" is where im having an error
any help would be greatly appreciated!
Answer by BiG · Jul 17, 2015 at 12:59 PM
The "standard" Start function, recognized by Unity, has the capital S.
void Start (){
rb = GetComponent<Rigidbody>();
}
Actually, your code skips that, and rb
is not initialized.
Your answer
Follow this Question
Related Questions
Roll-A-Ball Problem 2 Answers
roll-a-boll tutorial-rotator error 1 Answer
Problem for moving an object with a button 0 Answers
NullReferenceExeption 1 Answer
Having trouble getting the sample code for Mathf.PerlinNoise to work. 1 Answer