人物动画的控制和相机跟随

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();
        animator = GetComponent();

    }
	
	// 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);
        }
	}
}

 
 

你可能感兴趣的:(unity,C#)