Search Unity

If statement for yieldwaitforseconds possible?

Discussion in 'Scripting' started by Tezelian, Apr 9, 2014.

  1. Tezelian

    Tezelian

    Joined:
    Oct 22, 2013
    Posts:
    256
    I have several cut-scenes but want to find a certain time by using yeidlwaitforsecodns to pause the cut-scene and allow small interaction

    So I have a cut scene that lasts 2 minutes and at one minute or yield WaitForSeconds (60); I want to pause the time and allow interaction or the user to press a button to continue.

    So basically is something like

    if ( yield WaitForSeconds == 60)


    {

    time.Timescale = 0.0;
    //do something

    }
     
  2. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Try starting a timer instead :

    Code (csharp):
    1.  
    2. var timer : float;
    3. var timerTicking : boolean;
    4.  
    5. function Update(){
    6. if(timerTicking){
    7. timer += Time.deltaTime;
    8. }
    9. if(timer == 60){
    10. //Do Something
    11. }
    12. }
    13.  
    Just set "timerTicking" to true when your cut-scene starts. Hope that helps.
     
  3. Tezelian

    Tezelian

    Joined:
    Oct 22, 2013
    Posts:
    256
    I never actually thought of that, thank you very much, will try that


    Nonetheless is it possible to put yieldwaitforseconds in an if statement?
     
  4. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    I dont think so.
     
  5. pixelmechanic

    pixelmechanic

    Joined:
    Jan 8, 2014
    Posts:
    10
    No, yield WaitForSeconds will not work this way. The reason is, that WaitForSeconds doesn't return a value. So you haven't anything to compare to in your if-statement.

    Have a nice day ...
    pixelmechanic
     
  6. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    You could achieve the same behavior in a coroutine with no conditionals

    Code (csharp):
    1.  
    2. Debug.Log("Before waiting");
    3. yield return new WaitForSeconds(60);
    4. Debug.Log("I did something after 60 seconds");
    5.  
    Also - WaitForSeconds does return a value because it's an IEnumerator. It's just not particularly useful.
     
  7. Tezelian

    Tezelian

    Joined:
    Oct 22, 2013
    Posts:
    256
    Thank you very much guys, really appreciate the help

    Understand much more now.