- Home /
Unity's built in function OnBecameInvisible glitching?
I am currently making a mobile mini game with really simple code to make the player die.Basically i want my player to die if he is not rendered by any cameras (out of the screen) or if he hits a certain trigger. This is my code: void OnTriggerEnter(Collider collider){
if (collider.name == "SpikeObstacle(Clone)") {
playerIsDead = true;
}
}
void OnBecameInvisible(){
Debug.Log ("not working :/");
playerIsDead = true;
}
All its doing is registering if the player is "invisible" or if he touched a certain trigger and all its doing is setting a variable "playerIsDead" equal to true.
All good so far but when i play the game after one second (even though the player is in the middle of the screen) the bool playerIsDead turns true for some reason and the line "Debug.Log("not working :/");" that i used as a test to see whether or not it was OnBecameInvisible's fault is actually called. I have a renderer on the player and i should note that the same script worked for some reason just 2 days ago. I didnt just want to report something i wasnt sure about that's why I am posting this here first. There is no other code that turns the variable playerIsDead to true and for one second its actually false (as it should be) then it glitches.I am using Unity 5.3.5.Any help will be appreciated!