首页 > 移动平台 > 详细

Unity3D 移动和旋转

时间:2016-05-05 22:27:35      阅读:252      评论:0      收藏:0      [点我收藏+]

 

移动和旋转

using UnityEngine;
using System.Collections;
/*
 * Adminer:sun2955
 * http:www.yinghy.com
 * */
public class Move : MonoBehaviour {
    private float moveSpeed = 7;
    private float rotateSpeed = 150;
    
    // 使用进行初始化
    void Start () {
    
    }
    
    //每一帧都会调用该函数
    void Update () {

 
       //  float inputx = Input.GetAxis("Horizontal"); //获得水平移动
       // float inputy = Input.GetAxis("Vertical"); //获得垂直移动

       //// this.transform.Translate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime);

       // if(Input.GetKey(KeyCode.A)){
       //     this.transform.Rotate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime);
       // }
       // if (Input.GetKey(KeyCode.D))
       // {
       //     this.transform.Rotate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime);
       // }
    if(Input.GetKey(KeyCode.W)){
        this.transform.Translate(new Vector3(1, 0, 0)* moveSpeed * Time.deltaTime);
    }
    if (Input.GetKey(KeyCode.S))
    {
        this.transform.Translate(new Vector3(1, 0, 0) * -moveSpeed * Time.deltaTime);
    }
    if (Input.GetKey(KeyCode.A))
    {
        this.transform.Rotate(new Vector3(0, 1, 0) * -rotateSpeed * Time.deltaTime);
    }
    if (Input.GetKey(KeyCode.D))
    {
        this.transform.Rotate(new Vector3(0, 1, 0) *  rotateSpeed * Time.deltaTime);
    }
   
    }
    //物理运动
    void FixedUpdate() 
    {

    }
}

 

Unity3D 移动和旋转

原文:http://www.cnblogs.com/sunxun/p/5463454.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!