c# - Unity3d : object set to invisible for seconds -


i using coroutine alternate object visibility using renderer.enabled every 2 seconds, object doesn't wait 2 seconds change state, alternate between visible , non visible fast , randomly, it's looking unstable.

here code :

using unityengine; using system.collections;  public class arrowcontroller : monobehaviour {    gameobject arrow = null;  void start () {     arrow = gameobject.find ("arrow");     arrow.getcomponent<renderer> ().enabled = false; }  void update () {      startcoroutine(showdirection());   }        ienumerator showdirection(){             while (true) {         getcomponent<meshrenderer> ().enabled = true;         getcomponent<renderer> ().enabled = true;          yield return new waitforseconds (1);         getcomponent<meshrenderer> ().enabled = false;         getcomponent<renderer> ().enabled = false;          yield return new waitforseconds (1);     }      }   } 

that's because have startcoroutine in update method, fired every frame. so, start new coroutine every frame, , have hundreds of coroutines running @ same time.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -