- Home /
Clamp animation to a certain amount of time?
hey guys, finally getting back into unity. I've been laying down the framework code for my FPS game, and i was wanting the reload times to be easily customizable. So far it works just fine, but now that I've implemented animation, the animation finishes before the reload does (the gun is idling but unusable until the reload time is up). I've tried messing with the speed, but i cant seem to get it right. I was hoping there was a way to make the animation play over a certain amount of time.
Thanks, Joey
Answer by Benproductions1 · Mar 28, 2013 at 12:10 AM
Speed is the right thing to change, heres how:
//Just for typecasting
var reloadTime:float;
var animState:AnimationState;
//Now for setting the speed
animState.speed = reloadTime / animState.length;
All I did was set the speed to the multiplier the animations length needs to become the reload time (If that makes much sense)
Hope this helps,
Benproductions1
Oh thanks it does, i was doing 1 / reloadtime :p stupid of me. had to make it fit in to my weaponinfo class, but made it work, thanks very much. I'm learning C# so for any of you guys who see this:
public float reloadTime;
public AnimationState animState;
animState.speed = reloadTime / animState.length;
oh i didnt realize how similar they were lol just the way the variables are declared
Joey
OH WAIT almost forgot to mention, you flipped it The correct speed is actually the animState length / reloadTime lol :3
Joey
Your answer
Follow this Question
Related Questions
animation to play faster over time 2 Answers
[Solved] Reverse animation help 2 Answers
[Mecanim] How to manualy set the time on a state by code? 0 Answers
Mecanim - changing animation clip speed, through script? 4 Answers
Animation Stop and Stay 1 Answer