Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Time for shooting

Discussion in '2D' started by chas02068909, Dec 27, 2013.

  1. chas02068909

    chas02068909

    Joined:
    Sep 23, 2013
    Posts:
    21
    Hi.
    First I'm a beginner,

    Please I look for a solution for waiting moments between projectectiles instantiated
    The gun must wait between cartridges

    Thanks
     
  2. Tiggster

    Tiggster

    Joined:
    May 22, 2013
    Posts:
    29
    Create an integer counter variable and set it equal to zero. Then in your Update() method (or FixedUpdate() if you want to be consistent across machines and platforms) check to see if the variable is greater than or equal to the desired value for the pause (eg: 30 would approximately be one second, I believe), and if so, instantiate a new projectile based on a prefab and reset the value of the variable to zero. If the variable is not greater than or equal to your desired value, simply increment the variable.

    You could also generate a random number for the pause value if you want the time between projectiles being instantiated to vary.
     
  3. chas02068909

    chas02068909

    Joined:
    Sep 23, 2013
    Posts:
    21
    thank you :)