Search Unity

NullReferenceException

Discussion in 'Scripting' started by kirbyluong, Nov 26, 2015.

  1. kirbyluong

    kirbyluong

    Joined:
    Nov 26, 2015
    Posts:
    1
    using UnityEngine;
    using System.Collections;
    public class Player_movement : MonoBehaviour {

    public float Speed = 10;
    public GameObject cube;
    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);
    }
    }




    There was no error and everything was good but when I pressed the play button, The console started filling up with error, once i clicked on the error it showed me that rb.AddForce (movement * Speed) is the problem but I can't see any problem there, can someone help me?
     
  2. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Does the gameObject have a rigidbody on it. Also use
    Code (csharp):
    1.  tags when posting code
     
  3. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524