private Animator animator; public class playermove : MonoBehaviour { // Start is called before the first frame update void Start() { animator = GetComponent<Animator>(); } // Update is called once per frame void Update() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); Vector3 dir = new Vector3(horizontal, 0, vertical); if (dir != Vector3.zero) { transform.rotation = Quaternion.LookRotation(dir); animator.SetBool("Isrun", true); } else { animator.SetBool("Isrun", false) } } }
我是个初学者,在unity3D里写了个想按下按键时站立切换为跑步,但是不知道代码为什么一直报错,说是要为animator.SetBool("Isrun",true)和animator.SetBool("Isrun",false)引入本地变量,我不明白这是为什么,请您为我解答一下。代码如下: private Animator animator; public class playermove : MonoBehaviour { // Start is called before the first frame update void Start() { animator = GetComponent<Animator>(); } // Update is called once per frame void Update() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); Vector3 dir = new Vector3(horizontal, 0, vertical); if (dir != Vector3.zero) { transform.rotation = Quaternion.LookRotation(dir); animator.SetBool("Isrun", true); } else { animator.SetBool("Isrun", false) } } }