微信登录

Player - PlayerMove.cs - 玩家_移动

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerMove : MonoBehaviour {
  5. public float forward = 0;
  6. private float speed = 3;
  7. private Animator anim;
  8. // Use this for initialization
  9. void Start () {
  10. anim = GetComponent<Animator>();
  11. }
  12. // Update is called once per frame
  13. void FixedUpdate () {
  14. if (anim.GetCurrentAnimatorStateInfo(0).IsName("Grounded") == false) return;
  15. float h = Input.GetAxis("Horizontal");
  16. float v = Input.GetAxis("Vertical");
  17. if (Mathf.Abs(h) > 0 || Mathf.Abs(v) > 0)
  18. {
  19. transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime, Space.World);
  20. transform.rotation = Quaternion.LookRotation(new Vector3(h, 0, v));
  21. float res = Mathf.Max(Mathf.Abs(h), Mathf.Abs(v));
  22. forward = res;
  23. anim.SetFloat("Forward", res);
  24. }
  25. }
  26. }
Player - PlayerMove.cs - 玩家_移动