how to smoothly transition between animations in the "Any State" state machine.
so, I'm making a sign language project, and the way iv made it is if I have a word in my string, and it matches an animation I have in the "Any State" state machine, play animation. But they don't smoothly transition between each other. Here is what I have
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Asl : MonoBehaviour
{
private string[] strArray;
public string str = ("");
private int amount = 0;
private Animator anim;
public void Start(){
strArray = str.Split(' ');
anim = GetComponent<Animator>();
}
public void LateUpdate()
{
if(amount < strArray.Length)
{
anim.Play(strArray[amount]);
if(anim.GetCurrentAnimatorStateInfo(0).IsName(strArray[amount]) && anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f)
{
amount++;
}
}
else
{
anim.Play("Idle");
}
}
}
Answer by subamanis · Jan 20, 2021 at 08:24 PM
I am not sure what "they don't smoothly transition between each other" means, and I am not sure what you are trying to do. This code seems to be trying to play the animation that is associated with each string in the array once, and then go to idle state. If that is the case then:
1) From the parameter list of the animator, make one parameter of type Trigger for every state you have and give them names like the elements of the array ("no", "yes",...)
2) Make all the transitions that start from Any State start form Idle, and put as a condition the appropriate Trigger parameter
3) Connect all the states to Exit, and enable HasExitTime with a value of 1 for each transition
4) Make sure to set the Transition Duration of every transition in the animator to 0
5) Make a private variable count = 0;
6) Create the following method:
public void OnAnimationFinish()
{
if(count == strArray.Length) return;
anim.SetTrigger(strArray[count++];
}
7) In every animation, go to the last frame and right click to the area above and select Add Animation Event
8) From the inspector in your right, select as Function, the OnAnimationFinish one
Done. Delete the code in LateUpdate, it is far from optimal.
Thank you for your reply. Very sorry for not elaborating. $$anonymous$$y goal was to smoothly transition (for example), "No" to "Hello". $$anonymous$$y goal in the end is to have at least 100 or so animations, for words.