- Home /
How to make OnBecameInvisible call only when all children are off screen?
I have prefab tree, with children like trunk (cylinder), shadow (sprite)... I would like to reposition tree in front of player, when it's not visible on the screen any more. I'm trying to achieve that with OnBecameInvisible, but script needs to be on GameObject with renderer.
If script is attached to parent GameObject tree, to which I added empty MeshRenderer, OnBecameInvisible is called when center of tree goes off screen, even though trunk and shadow are still visible.
If script is attached to trunk, and reference passed to which object (parent - tree) should be moved, OnBecameInvisible is called when trunk is off screen, even though shadow is still visible.
? How can I make Renderer that is group off all children Renderers, so that OnBecameInvisible is called only when all children are off screen?
I would like to reopen this question as I find myself in the same situation. I am using Sprite Renderers for the children.
Random suggestion: rather than use OnBecomeInvisible, check the renderer.isVisible of all the objects.