Search Unity

yield WaitForSeconds/ Functions

Discussion in 'Scripting' started by filecity, Nov 15, 2009.

  1. filecity

    filecity

    Joined:
    Apr 21, 2009
    Posts:
    117
    hi, i have a problem here.
    Because the problem now is the yield WaitForSeconds is still counting.. How do I stop the function from executing halfway? And reset the function whenever I call it out again.

    Code (csharp):
    1.  
    2. function Update()
    3. {
    4. Move();
    5. }
    6.  
    7. function Move()
    8. {
    9. if(!cooldown)
    10. {
    11. cooldown = true;
    12. MoveLeft();
    13. yield WaitForSeconds(1);
    14. MoveRight();
    15. yield WaitForSeconds(1);
    16. MoveTop();
    17. yield WaitForSeconds(1);
    18. MoveBottom();
    19. cooldown = false;
    20. }
    21. }
    22.  
     
  2. oxl

    oxl

    Joined:
    Nov 21, 2008
    Posts:
    325
    Hi,

    not sure if I understand correctly, but you are calling your Move() Function in your Update loop, so it gets executed again and again every 3 seconds.

    Maybe you can bind the Move() Function to a key or to any other condition / event.

    --
    oxl