移动和旋转
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() { } }
时间: 2024-10-03 11:06:07