- Home /
Speed button for animations?
Total rube to scripting and struggling but surviving, mainly an artist. Have several looped animations that the user can choose from and watch but how do I give the user the option in changing the animation's to gradually speed up or down? Thanks!!!
Answer by efge · Mar 17, 2011 at 10:45 PM
Take a look at the reference for Animation:
// Make all animations in this character play at half speed
for (var state : AnimationState in animation) {
state.speed = 0.5;
}
thanks but how do i script it in a button style? sorry I'm so damn new to this. "The user clicks an up arrow and down arrow to speed the animation up or down. The animation maximum is 3X the speed and the $$anonymous$$imum is 2X slower." Thanks again.
Take a look at the next answer. You could also use a GUI.HorizontalSlider to change the speed between a $$anonymous$$ and a max.
Answer by FlintCLeaver · Mar 18, 2011 at 04:43 AM
You can use UNITY GUI to make some nifty buttons. make sure you define your animation state by either calling it every frame or make it a drag and drop variable for the editor.
not sure if all this will work as you want.
// use to define your Animation state. can be on a separate script but // make sure you make the variable GLOBAL.
var state : AnimationState;
function OnGUI() { // GUI related needs to be created in this function.
if (GUI.Button(Rect(10,10,50,50),"SlowDown")) //If you click on the GUI button // that reads "slowdown"
state.speed = 0.5; // slow down animation speed by half.
}