Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

NullReference Error for Fall Damage

Discussion in 'Scripting' started by WishPotato, Jul 8, 2014.

  1. WishPotato

    WishPotato

    Joined:
    Jul 8, 2014
    Posts:
    4
    Hey there Unity! So when I run the game i get spammed with the following error:
    "NullReferenceException: Object reference not set to an instance of an object
    FallDamage.Update () (at Assets/The Scripts/FallDamage.cs:20)"


    from this script in C#, I made a comment where the error should be:

    public class FallDamage : MonoBehaviour {

    public GameObject player;
    private ThePlayer playerScript;

    public float minFall = 2.0f;
    public float airTime = 0.0f;

    private CharacterController _controller;

    private void start(){
    _controller = GetComponent<CharacterController>();
    playerScript = player.GetComponent<ThePlayer>();
    }

    void Update(){
    if(!_controller .isGrounded){ // This is line 20 which is the cause of the error.
    airTime += Time.deltaTime;
    }
    if(_controller .isGrounded){
    if(airTime > minFall)
    {
    playerScript.currentHealth -= 2 * airTime;
    }
    airTime = 0;
    }
    }
    }
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    The proper method is "Start()", not "start()". It's case sensitive.
     
    IvanAuda and WishPotato like this.
  3. WishPotato

    WishPotato

    Joined:
    Jul 8, 2014
    Posts:
    4
    Oh... My...
    Wau... How can I over see that xD