I have many animations in many layers. At a time, I want to pause an animation in a certain layer and trigger/resume another animation in another layer, for example.
If I change the Animator.speed, it will affect all the animations within.
How can I resolve this? Thanks for your help.
I have multiple enemies on one layer on my level I want to start at different times and speeds so I have this piece of code
using UnityEngine;
public class AnimationControlerScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Animator anim = GetComponent<Animator>();
AnimatorStateInfo state = anim.GetCurrentAnimatorStateInfo(0);//could replace 0 by any other animation layer index
anim.speed = Random.Range(0f, 2f);
anim.Play(state.fullPathHash, -1, Random.Range(0f, 1f));
}
}
And I’m sure when looking for this I saw you could also target particular animations
anim["animationName"].speed = 1f;
So that mixed with AnimatorStateInfo should get you there
Thanks to @HoweToGaming I made a bit of research and find out there are already some answers, but none of them I see as clearly explained. I will make it simple.
Go to the Animator window, click on an animation state you want to adjust the speed, find Multiplier in the Inspector and check the Parameter checkbox, like this.
It will say you have to create a Float Parameter, so just create one called multiplier and set the default value 1.0, for example. The Inspector will be updated as below.
In the script, call animator.SetFloat(“multiplier”, speedScaleAsYouLike).
Unity will calculate the actual animation speed by multiplying them together.
Hope this helps.