Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

WaitForSeconds doesn t work?

Discussion in 'Scripting' started by PaxStyle, Jan 30, 2016.

  1. PaxStyle

    PaxStyle

    Joined:
    May 22, 2013
    Posts:
    63
    Hi there.. I would like to start the animaton after 5 seconds, so I added "yield WaitForSeconds (5)", but If I add that line, the animation doesn't start anymore.. why?

    Code (JavaScript):
    1.  var Animazione = "Vagone";
    2. var on : boolean;
    3. function Update () {
    4. if (Input.GetKey(KeyCode.Q)) {
    5. on = !on;
    6. if (!on){
    7. yield WaitForSeconds (5);
    8. GetComponent.<Animation>()[Animazione].speed = 0.5;
    9. GetComponent.<Animation>().Play(Animazione);
    10. }
    11. if (on) {
    12. }
    13. }
    14. }
     
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,032
    TaleOf4Gamers likes this.
  3. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Simply change:
    Code (CSharp):
    1. yield WaitForSeconds
    with:
    Code (CSharp):
    1. yield return new WaitForSeconds
     
  4. PaxStyle

    PaxStyle

    Joined:
    May 22, 2013
    Posts:
    63
    I changed It, but "yield return new WaitForSeconds (5);" give me the error: ';' expected. Insert a semicolon at the end.
     
  5. PaxStyle

    PaxStyle

    Joined:
    May 22, 2013
    Posts:
    63
    So I cannot use this in my script, because It can be used only in coroutines?
     
  6. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,032
  7. PaxStyle

    PaxStyle

    Joined:
    May 22, 2013
    Posts:
    63