I have an animation that lasts exactly 1 sec. I need to extend it to x sec using the variable “rTime”. For example, a variable is equal to 3 and the animation must be 3 seconds long, and the question is how to do that in code.,
I have an animation that lasts exactly 1 sec. I need to extend it to x sec using the variable “rTime”. For example, a variable is equal to 3 and the animation must be 3 seconds long, and the question is how to do that in code.
I’m not sure how to do it to an exact amount, but you can change the animator speed pretty easily.
Would probably be something like(untested)… – w/ ANIM_OnComplete() being called as an animation event from your animation, to reset the speed. Not sure how to get the length of an animation through code, so the knownLength value would need to be hardcoded.
Animator anim;
float knownLength = 1f;
void Awake(){
anim = GetComponent<Animator>();
}
void Do_SlowedAnim(){
anim.speed = knownLength / rTime;
}
public void ANIM_OnComplete(){
anim.speed = 1;
}