unity3d - Unityscript - how to best set a 5 second delay on an action that takes 5 seconds -


every time run section of code , press "d" key, unity crash. leads me believe there logic error have no idea going wrong.

 private var    delayamount         = 5.0;  private var    timedelay           = 0.0;  private var    abilityend          = 0.0;  public var     abilityduration     = 5.0;  public var     speed               = 2.0;   function update()  {       if (input.getkey ("d") && time.time > timedelay)     {            abilityend = time.time + abilityduration;         while(abilityend > time.time)         {            transform.translate(0, 0, time.deltatime * speed);         }         timedelay = time.time + delayamount;          }  } 

use if statement instead of while loop because loop doesn't break , unity overloads , crashes (don't quote me i'm no expert that's explanation).


Comments