unity3D 控制物體移動和動畫播放

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{
public float speed = 0.1F;
public float rotatespeed = 3.0f;
private Transform tran;
private Animator m_animtor;
private float h;
private float v;
// Use this for initialization
void Start()
{
tran = gameObject.GetComponent();
m_animtor = GetComponent();
}

// Update is called once per frame
void Update()
{
    h = Input.GetAxis("Horizontal");
    v = Input.GetAxis("Vertical");
    transform.Rotate(0, h * rotatespeed, 0);
    Vector3 forward = transform.TransformDirection(Vector3.forward);
    float curSpeed = speed * v;
    if (Mathf.Abs(v) > 0.1)
    {
        if (Input.GetKey(KeyCode.W))
        {
            //tran.Translate(Vector3.forward * 0.1f);
            //m_animtor.SetBool("walkone", true);8
            if (Input.GetKey(KeyCode.LeftShift))
            {
                tran.Translate(Vector3.forward * 0.5f);
                m_animtor.SetBool("runone", true);
            }
        }

        else if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.W))
        {

            m_animtor.SetBool("runone", false);
        }
        //else if (Input.GetKeyUp(KeyCode.W))
        //{
        //    m_animtor.SetBool("walkone", false);
        //}
        

    }

    if (Input.GetKey(KeyCode.K))
    {
        m_animtor.SetBool("attack", true);
    }
    else if (Input.GetKeyUp(KeyCode.K))
    {
        m_animtor.SetBool("attack", false);
    }

}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章