private Animator an;
void Start()
{
an = GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
an.SetFloat("Run",1);
an.SetBool("RunorWalk", true);
an.SetBool("Crouch", false);
}
if (Input.GetKeyDown(KeyCode.W))
{
an.SetInteger("Walk", 1);
an.SetBool("RunorWalk", false);
an.SetBool("Crouch", false);
}
if (Input.GetKeyDown(KeyCode.E))
{
an.SetTrigger("Jump");
an.SetInteger("Walk", 0);
an.SetFloat("Run", 0);
an.SetBool("Crouch", false);
}
if (Input.GetKeyDown(KeyCode.R))
{
an.SetBool("Crouch", true);
an.SetInteger("Walk", 0);
an.SetFloat("Run", 0);
}
if (Input.GetKeyDown(KeyCode.T))
{
an.SetBool("Crouch", false);
an.SetInteger("Walk", 0);
an.SetFloat("Run", 0);
}
}
在对象中添加组件Animator,再将动画换成人物动画
根据需要再选择动画是否循环
创建一个Animator文件夹,存放动画控制器
单击右键
选择animator controller
就可以开始了