Question by
Pejovski · Oct 28, 2015 at 01:09 AM ·
nullreferenceexceptionnullnull reference exceptionnullreferencenull exception
null reference exception help
I made spikes model and imported in unity and added Mesh Collider( convex + Is trigger), and made script if the player gets in collision with the spikes the level gets restarted. But i get this error nullreferenceexception object reference not set to an instance of an object. Here is my code:
#pragma strict
var gameMaster : GameMaster;
function OnTriggerEnter (colInfo : Collider)
{
if(gameMaster.isRestarting == false)
{
Debug.Log("Test");
if(colInfo.tag == "Player")
{
var destructible : Destructible = colInfo.GetComponent("Destructible") as Destructible;
destructible.Destruct();
}
gameMaster.RestartLevel();
}
}
how can i fix this?
Comment
Answer by whogas · Oct 28, 2015 at 04:39 AM
Are you defining which instance of GameMaster you want to use? In the inspector are you dragging a GameMaster object into the field for your local gameMaster? If not, then you need to set gameMaster equal to something in the code.
Which line number is the debugger pointing to as throwing this exception?