* -----英雄的移动控制 * * * * */ using System.Collections; using System.Collections.Generic; using UnityEngine; public class HeroMovingControl : MonoBehaviour { public float FloHeroMovingSpeed = 1F; //运动的速度 private CharacterController _ChaHeroControl; //英雄角色控制器 private Vector3 _VecHeroMoving; //英雄移动 // Use this for initialization void Start () { _ChaHeroControl = this.GetComponent<CharacterController>(); } // Update is called once per frame void Update() { //英雄的移动 _VecHeroMoving = Vector3.zero; if (Input.GetKey(KeyCode.W)) { _VecHeroMoving.z += FloHeroMovingSpeed * Time.deltaTime; } else if (Input.GetKey(KeyCode.S)) { _VecHeroMoving.z -= FloHeroMovingSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.A)) { _VecHeroMoving.x -= FloHeroMovingSpeed * Time.deltaTime; } else if (Input.GetKey(KeyCode.D)) { _VecHeroMoving.x += FloHeroMovingSpeed * Time.deltaTime; } //Move()方法必须使用世界坐标系 _ChaHeroControl.Move(this.transform.TransformDirection(_VecHeroMoving)); } }