Question by
shinobi_7373 · Nov 10, 2015 at 04:57 PM ·
unity 5roll a ball
I am new to unity and am trying to do the roll-a-ball game, but when I try to run it, I get this error: NullReferenceException: Object reference not set to an instance of an object. What am I doing wrong?
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 * speed);
}
}
Comment
it would help others if you posted the complete error message, including line number. please try to do so in future posts.
in this case, however, it's most likely that the problem is line 7 - the function should be called Start()
, not start()
. case is important.
Your answer
Follow this Question
Related Questions
Roll A Ball Beginner Tutorial in Android controls 1 Answer
orbiting mouse controlled camera goes through terrain 0 Answers
Blend generated fbx import to unity problem 1 Answer
Public Variables Behave as Static 1 Answer
Tagging Doors and Windows 0 Answers