- Home /
 
Looping Animation Event to only fire once?
Hey all,
I have an Animation that is on a loop, however within this Animation is an event which I wish to fire off only once, it fires of the ShowMe function, on every loop, and ideally this would only happen one.
How can I do this?
I'm using code found here: http://forum.unity3d.com/threads/177...o-do-subtitles
  var myStrings : String[];    
         var curString : int = 0;    
         var displaying : boolean = false;    
         var myStyle : GUIStyle;
          
         function ShowMe(hit : int)
             {
                curString = hit;
                displaying = true;
                yield WaitForSeconds((myStrings[curString].length / 10) + 1);
                displaying = false;
             }
          
         function OnGUI()
             {
                if (displaying) {
                   GUI.Label(Rect(20, Screen.height - 80, Screen.width - 40, 60), myStrings[curString], myStyle);
                }
             }
 
               Thanks, Josh.
Answer by Screenhog · Nov 27, 2012 at 07:12 PM
The easiest way is to track if you've fired ShowMe() with a variable:
 var showMeHasHappened: boolean = false;
     
 function ShowMe(hit : int) {
     if (!showMeHasHappened) {
         curString = hit; 
         showMeHasHappened = true;
         displaying = true;
          yield WaitForSeconds((myStrings[curString].length / 10) + 1);
          displaying = false;
     }
 }
 
              Your answer
 
             Follow this Question
Related Questions
How can you check for player input during specific frames of an animation? 1 Answer
Animation Events added with code seem to be at wrong time 0 Answers
Is there a way to select animation events on the dopesheet beside clicking on them? 0 Answers
Animation Events do not trigger 0 Answers
"Animation Rigging" package and animation events - do they work together? 0 Answers