Hi there.This is my first post as up till now i have been able to figure out my mistakes or find another way to approach the problem.But this time I am stuck and would like some advice and help.
I checked my scripts multiple times and found no flaws.Also checked that all game objects that are called are in the correct poistions and that the correct scipt is attached to them.And the game works but when i get hit by an enemy it says that there is NullReferenceException.But I can’t seem to find where the NullReferenceException is located in my script.
(By the way i have encountered similar problems with NullReferenceException and have been able to fix them till now)
GameConroller is the script that contains the variable lives.I use the following to call a function from another script in order to subtract lives and respwan the player once hit.`
GameController.lives -= 1;
if(GameController.lives > 0)
It says that my nullreference exception occurs in the if statement above.
This statement is inside an OnTriggerEnter function so that when the enemy bullet hits the player the player dies.
Respawn is the function that is being called from other script and inside that function I have the following :
Instantiate(Player, Vector3(-0.1, 0.5, -4), transform.rotation);
I know that unity is telling that the problem is inside my if statement but i just can’t see it.
All help and advice is welcome.