Search Unity

No Sounds with Yield?

Discussion in 'Scripting' started by xacto, Sep 9, 2005.

  1. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    I am trying to load a scene after 3 seconds of playing a sound, however as soon as I add a yield statment - the sound does not play. Is there another way around this?

    Thanks!


    Code (csharp):
    1.  
    2. function OnCollisionEnter () {
    3.  
    4. guiComment.text = "you win!!! " ;
    5. if (audio  !audio.isPlaying) {
    6.             audio.Play ();
    7.         }
    8. yield WaitForSeconds(3.0); 
    9. Application.LoadLevel("CarnScreenStart");          
    10. }
    11.  
    12.  
    13.  
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    At the moment Event handlers eg. OnCollisionEnter can not be coroutines. (A function using yield is a coroutine)
    I am hoping to get this bug fixed for 1.1.1.

    As a workaround you could create another function which does the yield thing and call it using StartCoroutine.
     
  3. xacto

    xacto

    Joined:
    Jul 20, 2005
    Posts:
    112
    Thank you, will give that a try!