2

i just started working in unity3d.
i have this class

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    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); 
    }
}

it displays an error :

NullReferenceException: Object Reference not set to an instance of an object.
line : 11 {rb.AddForce(movement)}

please share if anyone knows what's the problem and how to solve it.

Sandeep
  • 1,474
  • 6
  • 20
  • 32
  • 1
    Gonna guess that `rb` is null so you're `start` method is either not being called, or `GetComponent` is returning null. – Steve Mar 11 '16 at 05:22

1 Answers1

5

You wrote the start method with a small "s". So it is not called by Unity engine.

void Start() will work. Notice the capital "S".

JoRouss
  • 2,740
  • 2
  • 19
  • 40