- Home /
Null Refrence Exception
this error keeps poping up resulting in my game crashing after about 6 seconds, iv e tried removing this element and and putting it back in and re connecting each part (its a switch and a door script btw.
Screenshot is totally unreadable. Please post the script =]
Ok , i found I can view image :S
http://answers.unity3d.com/storage/temp/941-Screen+shot+2012-05-17+at+14.23.57.png
Could you post the full error message as well , your highlighted line does seem fine. Although it's almost the same thing (and doesn't answer your qn), you could try :
Vector3.magnitude(player.transform.position - transform.position);
check if something is attachedto objectToDestroy variable!!
Answer by Berenger · May 17, 2012 at 03:49 PM
The only nullreference you can get here, if the error is generated by the code in your screenshot, is if the player isn't found. The variable player would then be null.
You should'nt search for it every frame though. Do it once at start, or if it can change do it only when the change occurs (the player die, for example)
Your answer
Follow this Question
Related Questions
problem at adding script 1 Answer
Camera's wont change 2 Answers
BCE0044: Expecting : Found = Error! 2 Answers
insert a semicolon at the end?? 1 Answer
Error when trying to add script to game object via editor. 2 Answers