using System.Collections; using System.Collections.Generic; using UnityEngine; public class move02 : MonoBehaviour { //my animator public Animator myanimator; // local velocity Vector3 velocity; // Start is called before the first frame update void Start() { } // Update is called once per frame void FixedUpdate() { float x1 = Input.GetAxis("Horizontal"); float v1 = Input.GetAxis("Vertical"); //設定animator裡面的參數speed = v1 myanimator.SetFloat("speed", v1); //設定animator裡面的參數direction = x1 myanimator.SetFloat("direction", x1); //下面是角色移動處理 //從向上和向下鍵輸入獲取Z軸方向的移動量 velocity = new Vector3(0, 0, v1); // 轉換為角色的局部空間方向 velocity = transform.TransformDirection(velocity); // 按下向上和向下鍵移動角色 transform.localPosition += velocity * Time.fixedDeltaTime; //通過按左右鍵在Y軸上旋轉字符 transform.Rotate(0, x1*2.0f, 0); } }