unity3d控制模型的运动
这里就不多做解释了,直接上代码,只为了备忘。
public class HeroMove : MonoBehaviour { private float speed;//人物行动速度 private Animation ani; // Use this for initialization void Start () { speed = 1f; ani = GetComponent<Animation> (); } // Update is called once per frame void Update () { /*向前走/跑*/ if (Input.GetKey (KeyCode.W)) { transform.Translate (Vector3.forward * Time.deltaTime * speed); if (Input.GetKey (KeyCode.LeftShift)) { speed = 3f; ani.Play ("Run"); } else { speed = 1f; ani ["Walk"].speed = 1; ani.Play ("Walk"); } } else if (Input.GetKey (KeyCode.S)) { //向后退 transform.Translate (Vector3.back * Time.deltaTime * speed); ani ["Walk"].speed = -1; ani.Play ("Walk"); } else { //停止 ani.Play ("Idle"); } } }
** Then I looked up at the sky and saw the sun **
posted on 2017-06-20 00:24 chenyangsocool 阅读(423) 评论(0) 编辑 收藏 举报