美文网首页
unity5 操作移动脚本方法

unity5 操作移动脚本方法

作者: 自由的天空 | 来源:发表于2016-04-22 09:20 被阅读814次

    public float speed=10;

    float rotSpeed = 5;

    void Start()

    {

    }

    void Update()

    {

    float Horz = CrossPlatformInputManager.GetAxis("Horizontal");

    float vert = CrossPlatformInputManager.GetAxis("Vertical");

    Quaternion yrot = Quaternion.Euler(0, rotSpeed* Horz*Time.deltaTime, 0);

    transform.rotation *= yrot;

    transform.position += transform.forward *vert *speed *Time.deltaTime;}

    方法二  charactercontroller

    public float speed=10;      float rotSpeed = 5;   

     CharacterController thisCharacter;  

      void Start()    {        t

    hisCharacter = this.GetComponent();

    }

    void FixedUpdate()

    {

    float Horz = CrossPlatformInputManager.GetAxis("Horizontal");

    float vert = CrossPlatformInputManager.GetAxis("Vertical");

    if (Horz != 0)

    {

    Quaternion yrot = Quaternion.Euler(0, rotSpeed * Horz * Time.deltaTime, 0);

    transform.rotation *= yrot;

    }

    thisCharacter.SimpleMove(transform.forward * vert * speed );

    }

    相关文章

      网友评论

          本文标题:unity5 操作移动脚本方法

          本文链接:https://www.haomeiwen.com/subject/exfxrttx.html