这里就不多做解释了,直接上代码,只为了备忘。

public class HeroMove : MonoBehaviour {

    private float speed;//人物行动速度
    private Animation ani;

    // Use this for initialization
    void Start () {
        speed = 1f;
        ani = GetComponent<Animation> ();
    }
    
    // Update is called once per frame
    void Update () {
        /*向前走/跑*/
        if (Input.GetKey (KeyCode.W)) {
            transform.Translate (Vector3.forward * Time.deltaTime * speed);
            if (Input.GetKey (KeyCode.LeftShift)) {
                speed = 3f;
                ani.Play ("Run");
            } else {
                speed = 1f;
                ani ["Walk"].speed = 1;
                ani.Play ("Walk");
            }
        } else if (Input.GetKey (KeyCode.S)) {
            //向后退
            transform.Translate (Vector3.back * Time.deltaTime * speed);
            ani ["Walk"].speed = -1;
            ani.Play ("Walk");
        } else {
            //停止
            ani.Play ("Idle");
        }
    }
}

 

相关文章:

  • 2021-06-07
  • 2021-09-13
  • 2022-01-16
  • 2022-12-23
  • 2021-12-23
  • 2021-06-18
  • 2021-12-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-15
  • 2021-07-26
  • 2021-09-27
  • 2022-02-28
  • 2021-09-05
相关资源
相似解决方案