- Home /
OnBecameInvisible not working for Sprite
I have a 2d game I am using sprites on (so using sprite renderer, not sure if that is my problem) that is very similar to flappy birds. I have an empty GameObject that has a script attached to it that spawns prefabs of an object that has been dropped into the script (one empty GameObject has has attached the one that spawns ground sections, another the copies of the obstacle). My problem is that I cannot get OnBecameInvisible to run while the program is going and I cannot figure out why and was hoping for some suggestions. Below is what I am trying to run, and I have tried variations of it, but no dice.
void OnBecameInvisible(){
Destroy (gameObject);
}
If you're running in the editor, the scene camera counts for visibility checks. You might attach a script that checks the renderer's isVisible property once per frame, just to make sure things are behaving the way you expect.
Answer by JayJennings · Mar 10, 2015 at 09:40 AM
I believe the OnBecameInvisible message is sent to scripts attached to the renderer that goes offscreen, so if it's attached to your onscreen spawner game object, it will never be called.
Instead, put that in a script attached to the game object that should be destroyed.
Answer by A-GreatMother · Aug 13, 2015 at 01:34 PM
you know what?try maximize the game window when you run you game in editor,if the sprite is visible in scene ,it still "visible",check the API carefully.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How can I change the Value of a Color through script? 1 Answer
Sprite on SpriteRenderer not keyframing? 1 Answer
tk2d change tk2dSprite's Sprite value at runtime 3 Answers
Sprite Overlap why? 0 Answers