- Home /
 
               Question by 
               Kiwi2703 · Feb 04, 2014 at 06:11 PM · 
                javascriptyieldwaitforseconds  
              
 
              Yield WaitForSeconds doesn't work
Hi there :) I'm creating and testing subtitles in my game. I have an empty object called "SubtitlesObj", with a GUIText component on it (those are the subtitles). I have this script attached to it:
 public var Subtitles : GameObject;
 public var Subs : GUIText = Subtitles.GetComponent("GUIText");
 
 function Update () {
     
         if(Input.GetKeyDown ("space")){
              Debug.Log("jumped");
              SubsSay("Thump!!","2");
         }
         
 }
 
 function SubsSay(SubsText,SubsDuration){
     Subs.text = SubsText;
     yield WaitForSeconds(SubsDuration);
     Subs.text = "-nothing-";
 }
But it doesn't work. I want the subtitles to say "Thump!!" when player presses space, then wait for 2 seconds and change the subtitle to "-nothing-" (for testing purposes). However, the yield command doesn't seem to work. When I remove it, the subtitles change to "-nothing-" when space is pressed. But when the yield command is there, it gives me an error and the "Thump!!" subtitle stays there forever. Can you help me with that please? Thank you!
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by rednax20 · Feb 04, 2014 at 06:25 PM
  SubsSay("Thump!!","2");
"2" should be an integer/float.
 //change it to this
  SubsSay("Thump!!",2);
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                