using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMove : MonoBehaviour { public float velocity = 5; Rigidbody m_rigidbody; private Animator animator; void Awake() { } // Use this for initialization void Start () { m_rigidbody = GetComponent<Rigidbody>(); animator = GetComponent<Animator>(); } // Update is called once per frame void Update () { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); Vector3 noeVelocity = m_rigidbody.velocity; if (Mathf.Abs(h) > 0.05 || Mathf.Abs(v) > 0.05f) { m_rigidbody.velocity = new Vector3(-velocity * h, noeVelocity.y, velocity * v); animator.SetBool("Move", true); //修改朝向 transform.LookAt(new Vector3(-h, 0, v)+transform.position); } else { m_rigidbody.velocity = new Vector3(0, noeVelocity.y, 0); animator.SetBool("Move", false); } } }
人物动画的控制和相机跟随
最新推荐文章于 2021-12-15 13:41:33 发布