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

Problem With Unity Tutorial Project - Stealth

Discussion in 'Editor & General Support' started by Ronpo2, May 17, 2014.

  1. Ronpo2

    Ronpo2

    Joined:
    May 17, 2014
    Posts:
    4
    Hi everyone.

    I'm learning who to use Unity from Unity's made tutorial for a game step by step, but I think that because I have newer version then there is in the video I'm trying to write a script as they do and it shows me that there's an Error.

    My problem is in this line:
    alarm = GameObject.FindGameObjectWithTag ("Alarm").GetComponent<AlarmLight> ();

    But I'm pretty sure that only see the code isn't much helpful...
    So here a link to the video:
    http://unity3d.com/learn/tutorials/projects/stealth/game-controller

    Thank you to all the helpers, and even the one's who only read it.
     
  2. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Post the error here. Can't really help you if you don't give us the error. Perhaps you haven't set the "Alarm" tag yet?
     
  3. Ronpo2

    Ronpo2

    Joined:
    May 17, 2014
    Posts:
    4
    Here the problem:
    NullReferenceException: Object reference not set to an instance of an object
    LastPlayerSighting.Awake () (at Assets/Scripts/LastPlayerSighting.cs:22)

    Is it helps?
     
  4. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    It does. Is there an object in the scene with the tag of "Alarm" (not "alarm"!) and does that object have a component attached to it called "AlarmLight"? If any of those are missing you'll get that error.
     
  5. Ronpo2

    Ronpo2

    Joined:
    May 17, 2014
    Posts:
    4
    No, there isn't an object in the scene with the tag of "Alarm", but I have a line:
    private AlarmLight alarm;
    (Reference to the AlarmLight script)
     
  6. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Well, that's your problem then. Put one in and make sure it has the script "AlarmLight" attached to it. I suspect it needs to be a light of some sort but I'm not going to watch that entire video just to find out for you.
     
  7. Ronpo2

    Ronpo2

    Joined:
    May 17, 2014
    Posts:
    4
    Ok, so can you tell me how to attach the script "AlarmLight" to it?
     
  8. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    With the "Add Component" button. Or you can drag the script right on to the object. Doesn't the tutorial tell you how to do all this? if not, you need to go back and do some very beginner tutorials. This kind of stuff should be the first thing you learn.
     
  9. FarumDigitalProduction

    FarumDigitalProduction

    Joined:
    Aug 3, 2014
    Posts:
    1
    I had the same problem. I tried correcting possible typos. It didn't help. I tried identifying what object wasn't found by breaking the statement into two. It was the light that wasn't found. Then I discovered that I had accidentaly disabled the light_alarm_directional when I played around with it before I wrote the script.