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

Having trouble with getting my doors to work.

Discussion in 'Scripting' started by Todd S., Feb 22, 2015.

  1. Todd S.

    Todd S.

    Joined:
    Feb 22, 2015
    Posts:
    1
    If anyone can give me a little direction that would be great.

    This is the error message I'm getting.
    NullReferenceException: Object reference not set to an instance of an object
    BaseDoor.Update () (at Assets/BaseDoor.cs:29)
    InputDoor.Update () (at Assets/InputDoor.cs:16)

    My BaseDoor code:
    _______________________________________________________________
    upload_2015-2-22_1-39-50.png
    _______________________________________________________________
    My InputDoor code:
    _________________________________________________________________
    upload_2015-2-22_1-41-27.png
    _______________________________________________________________________

    upload_2015-2-21_21-58-17.png
     
    Last edited: Feb 22, 2015
  2. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    490
    Please use code tags instead of just posting scripts as text, it makes it much easier to read and numbers each line. That way we can jump straight to lines 29 and 16 instead of puzzling out which lines those are. To use code tags look for the insert icon and select "code" from the dropdown menu.

    From the looks of it I'm guessing you're trying to access functions in other scripts, such as your InputDoor script accessing the update function of your BaseDoor script. This is a rundown of how that works: http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

    I didn't check the BaseDoor script, but in your InputDoor script you're calling the update function on "base" without defining what "base" is.
     
  3. Oleygen

    Oleygen

    Joined:
    Feb 21, 2015
    Posts:
    24
    base is a key-word which ref to parent in C#
     
  4. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    490
    Aah, my apologies. I rarely mess with C#.