?? ??? ??? ?float h = Input.GetAxis("Horizontal"); ?? ??? ??? ?float v = Input.GetAxis("Vertical"); ?? ??? ? ? ?Vector3 pos = Vector3.zero;
?? ??? ?//按下键盘使玩家走动/. ?? ??? ?if (h != 0 || v != 0) ?? ??? ??? ?{ ?? ??? ??? ??? ?//转方向 ?? ??? ??? ??? ?if (h < 0)//左边 ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?transform.rotation = Quaternion.Euler(0, -90, 0); ?? ??? ??? ??? ??? ?pos = transform.forward * v + transform.right * -h;//控制前后左右 ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (h > 0)//右边 ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?transform.rotation = Quaternion.Euler(0, 90, 0); ?? ??? ??? ??? ??? ?pos = transform.forward * v + transform.right * -h; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (v < 0)//后面 ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?transform.rotation = Quaternion.Euler(0, 180, 0); ?? ??? ??? ??? ??? ?pos = transform.forward * v + transform.right * h; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (v > 0)//前面 ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?transform.rotation = Quaternion.Euler(0, 0, 0); ?? ??? ??? ??? ??? ?pos = transform.forward * v + transform.right * h; ?? ??? ??? ??? ?} ?? ??? ??? ?//an.Play("Walk"); ?? ??? ??? ?//先切换到Walk状态,然后再调用Walk动画 ?? ??? ??? ? ? ps = PlayerState.Walk; ?? ??? ? ? ? ? GetState(ps);
?? ??? ??? ??? ?transform.Translate(pos * Time.deltaTime * speed);
|