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 ();
But I’m pretty sure that only see the code isn’t much helpful…
So here a link to the video:
Thank you to all the helpers, and even the one’s who only read it.
Here the problem:
NullReferenceException: Object reference not set to an instance of an object
LastPlayerSighting.Awake () (at Assets/Scripts/LastPlayerSighting.cs:22)
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.
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.
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.
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.