Quantcast
Channel: Answers for "C# OnBecameVisible turning of particles and effects"
Viewing all articles
Browse latest Browse all 4

Answer by GameVortex

0
0
I am a little unsure of what you are trying to accomplish with turning everything off like that. Animations by default does not play while off screen and particles are not rendered. But it seems you have mostly figured it out yourself though: Disable the object when OnBecameInvisible() is called. For that you use the gameObject.SetActive(false) function. Example: private void OnBecameInvisible() { gameObject.SetActive(false); } This disables everything on the gameObject though. Which means the OnBecameVisible will never be called as the objects renderer is turned off. Maybe you only want to disable animations and particle effects explicitly? Do that by finding the animation or particle system component and disabling them. Example: private void OnBecameInvisible() { ParticleSystem ps = GetComponent(); if(ps) { ps.Stop(); } //Monobehaviour already has a variable to animation if(animation) { animation.Stop(); } } Then you can turn them on again when the object becomes visible.

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images