Hello! I want to play only one frame of an animation clip inside a RuntimeAnimatorController that is an AnimatorOverrideController. I’m using 2d.
I get no errors on console but the sprite does not change.
I used a prefab and assigned the RuntimeAnimatorControllers.
Edit: I need to use the others animator controllers to change the animation too.
My current code is:
public class Sample : MonoBehaviour
{
public RuntimeAnimatorController animator2;
public RuntimeAnimatorController animator3;
public float timeBetweenChanges = 0.3f;
private Animator _animator;
public enum MyAnimatorTypes
{
animator2 = 0,
animator3 = 1
}
void Start()
{
_animator = (Animator)GetComponent(typeof(Animator));
}
IEnumerator _crChangeType()
{
yield return new WaitForSeconds(timeBetweenChanges);
_ChangeType();
StartCoroutine(_crChangeType());
}
private void _ChangeType()
{
MyAnimatorTypes newType = MyAnimatorTypes.animator2;
switch (newType)
{
case MyAnimatorTypes.animator2:
_animator.runtimeAnimatorController = animator2;
break;
case MyAnimatorTypes.animator3:
_animator.runtimeAnimatorController = animator2;
break;
}
AnimatorStateInfo asi = _animator.GetCurrentAnimatorStateInfo(0);
_animator.Play(asi.shortNameHash, 0, 0f);
}
}