標籤:
移動和旋轉
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 移動和旋轉