Can anyone tell me why I get an error from the following code?
I’m trying to reference a C# script (from another C# script in the same project) called HazardSpawner. I’m trying to de-activate it…
HazardSpawner hazardSpawner;
void Awake ()
{
hazardSpawner = GetComponent <HazardSpawner> ();
hazardSpawner.enabled = false;
}
EDIT: here is the resulting error:
NullReferenceException: Object reference not set to an instance of an object
PlayerHealth.Awake () (at Assets/Scripts/PlayerHealth.cs:28)