码迷,mamicode.com
首页 > 编程语言 > 详细

unity3d控制模型的运动

时间:2017-06-20 01:05:11      阅读:408      评论:0      收藏:0      [点我收藏+]

标签:shift   call   update   init   ini   led   one   getc   wal   

这里就不多做解释了,直接上代码,只为了备忘。

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");
        }
    }
}

 

unity3d控制模型的运动

标签:shift   call   update   init   ini   led   one   getc   wal   

原文地址:http://www.cnblogs.com/chenyangsocool/p/7051277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!