- Home /
Animation control using Events and .enable
(unity 3.5.6 c#)
I have a menu to control the flow of an animation, which is stopped several times using the Animation event to call out to a function that sets the .enabled = false;
This allows me to setup animations that can be controlled for learning a process. The features I have working (with a small hicup) are to allow the learner to move backwards and forwards in the animatin stopped by the Animation Event Markers. So each animation can have X steps (markers) and the user can start the animation, see 1 step, and then get some info, then using a button to continue the animation or reverse it.
All works, but when hitting REVERSE or speed=-1 I have to hit that button twice the first time, but if I keep hitting it, it works fine. So its like the reverse was being ignored the first time and it hit the same Event and stopped, but when I hit it again, it then plays backwards and goes to the previous event.
(confused, sorry, not a great writter)
I have setup 2 scripts, one on the Animation Object, and another on an object you click to start the menu items, which control the animation.
Here are examples of what I have (each event has its own function just for controll options)
Note the name of the clip is found in the AWAKE by doing foreach in the AnimationState
AnimationController.cs
void HaltAnimation01() {
animation[DaAnimationCip.name].enabled = false;
}
then the script with the GUI that has a play button, up and down arrows to move 1 step forward or backward. The UP and Down Arrows are what is not working on 1 click, but takes 2 to make it catch.
SequenceTrigger.cs (partial)
if (GUI.Button (new Rect(0,0,32,32),GUIContent.none, "UpArrow") {
WAR_FPC.animation["test1"].speed = -1;
WAR_FPC.animation["test1"].enabled = true;
}
I have tried putting the -1 after the enabled, and even tried putting a play after it, but it still does the same thing.
If animation has gone to event 3, I hit the UP Arrow to reverse the animation to Event 2. Its seems to play to Event 3 again and stop (realy quick blip) I press the UP arrow again, and it reverses to Event 2, like I wanted, but it takes 2 presses to start the -1 flow. But... if I keep pressing UP, it works on the first press, so it seems the initial reversing of the flow is not being set correctly or in the correct way? It also does this when I press DOWN after getting the reverse to play same code, but Positive 1.
How can I make it reverse on just 1 click (rather than 2)?
Answer by wkmccoy · Mar 08, 2013 at 02:37 PM
Ok, I got a better play back response out of using the .speed = 0 rather than .enabled = false (and then true) So setting the speed to 0, then 1 or -1 creates a smooth flow and does not force a 2 click to make it reverse direction. Not sure if there is a hit on performance whie the animatin is still, but so far its smooth and repsonsive.