using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 3;
private Animator anim;
void Awake()
{
anim = this.GetComponent<Animator>();
}
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if (Mathf.Abs(h) > 0.1f || (v) > 0.1f)
{
float newSpeed= Mathf.Lerp(anim.GetFloat("Speed"), 5.6f, Time.deltaTime * moveSpeed);
anim.SetFloat("Speed",newSpeed);
}
else
{
anim.SetFloat("Speed", 0);
}
}
}
我是用的是U3D 2017,动画状态机也略有不同
设置如上,开始游戏后,按下方向键需要两秒角色才会从Idel变为Run。