Add an animation state machine

Add an animation state machine

Click an animation, click a right mouse button and select the second option to build animation switching

Controller places the animation state machine you set

Avatar is your character skeleton

Apply Root Motion Check this option. When the character animation is played, it will move according to the instructions under the feet. Under normal conditions, do not check it.

 

public class Rotos : MonoBehaviour {
	private Animator an;
	void Start () {
		an= GetComponent<Animator>();//添加鑫动画的组件
	}
	
	void Update () {
		if (Input.GetKeyDown(KeyCode.Q))//播放跑的动画
		{
			an.SetFloat("Run", 1.0f);    //小数类型
			an.SetBool("RunANDWalk", true);//布尔类型
		}
        if (Input.GetKeyDown(KeyCode.W))//播放走
        {
			an.SetInteger("Walk", 1);//int类型
			
        }
        if (Input.GetKeyDown(KeyCode.E))//播放跳
        {
			an.SetTrigger("Jump");//触发器类型
        }
    }
}

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Optimistic_lx/article/details/129289981