unity3d - Unity 2D - Why can not the enemy made? -


i making running game, face big problem. in stage, obstacles created. after time, unity didn't make new obstacle. why happen?

public class gamemanager : monobehaviour {     public float waitingtime = 1.5f;     public static gamemanager manager;     public bool ready = true;     public gameobject cactus;     float time = 0;      // use initialization     void start () {         manager = this;     }      // update called once per frame     void update () {         time += time.deltatime;         //debug.log(time);         if(time>2f && ready==true)         {             ready = false;             time = 0;             invokerepeating("makecactus", 1f, waitingtime);         }     }     void makecactus()     {         instantiate(cactus);     }    public void gameover()     {         //cancelinvoke("makecactus");         itween.shakeposition(camera.main.gameobject, itween.hash("x", 0.2, "y", 0.2, "time", 0.5f));     } } 

you don't need update method @ all. using delay spawning. code can re-written this:

public class gamemanager : monobehaviour  {     public float waitingtime = 1.5f;     public static gamemanager manager;     public gameobject cactus;      void awake()      {         manager = this;         invokerepeating("makecactus", 3f, waitingtime);     }      void makecactus()     {         instantiate(cactus);     }      public void gameover()     {         //cancelinvoke("makecactus");         itween.shakeposition(camera.main.gameobject, itween.hash("x", 0.2, "y", 0.2, "time", 0.5f));     } } 

hopefully solve problem


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -