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

来源:互联网 发布:欧莱雅淘宝旗舰店 编辑:程序博客网 时间:2024/04/30 06:16
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 framevoid 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);        }}}

 
原创粉丝点击