I cant by the love of all things good, understand why I get the error: NullReferenceException: Object reference not set to an instance of an object MonsterSpawner.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/MonsterSpawner.cs:25)
this is the part of the script that seems to be wrong? The particular line it is coplaining about is: if (!objectHit.getIsMonster())
The wierd thing is that everything is working as it is supposed to do? And the if sentence works as intended as well? Its just annoying getting the error, and I would like to get rid of it.
asked Sep 19 '10 at 03:08 PM
It must be the case that the object which was collided with did not have a "DamageManagement" component at all (and therefore 'objectHit' would be null).
Since you're not checking whether it's null, you'll get this error.
To correct it, try this modification, which includes an explicit check for a null reference:
hope this solves the problem!
answered Sep 19 '10 at 03:59 PM
To those interrested, this is what the working code now looks like. Again, thanks Duck :) You made my sunday evening so much greater! :D
answered Sep 19 '10 at 05:45 PM