0
我正在创建一个赛车游戏,我希望我的车左右移动一点旋转 这是我迄今为止所做的,但问题是当键是按下物体旋转,但 不会回到原来的旋转,我想要的是,当按下键时,它应该旋转,但按下按键一秒后,它应该返回到其原始旋转。 这里是剧本我至今..返回对象旋转后的x时间量的原始旋转
using UnityEngine;
using System.Collections;
public class CarKeyboardMovement : MonoBehaviour {
public GameObject car;
public GameObject vehicle;
public float turnSpeed = 20f;
private bool spinning = false;
public float speed = 20;
Quaternion originalRotation;
public bool restorerotation = false;
public float timer = 0.0f ;
public float xtimer = 0.0f;
public float limittimer = 1f;
void Start() {
originalRotation = vehicle.transform.rotation;
}
// Update is called once per frame
void Update() {
if (Input.GetKey (KeyCode.Z) && !spinning) {
car.transform.Translate (Vector3.left);
vehicle.transform.Rotate (Vector3.up, speed * Time.deltaTime);
timer -= Time.deltaTime;
timer +=Time.deltaTime;
restorerotation =true;
if(restorerotation && limittimer < timer)
{
vehicle.transform.Rotate (Vector3.up, -speed * Time.deltaTime);
if(transform.rotation == originalRotation)
{
restorerotation = false;
timer = 0f;
}
}
}
if (Input.GetKey (KeyCode.V)&& !spinning) {
car.transform.Translate (Vector3.right);
vehicle.transform.Rotate (Vector3.up, -speed * Time.deltaTime);
timer -= Time.deltaTime;
timer +=Time.deltaTime;
restorerotation =true;
if(restorerotation && limittimer < timer)
{
vehicle.transform.Rotate (Vector3.up, speed * Time.deltaTime);
if(transform.rotation == originalRotation)
{
restorerotation = false;
timer = 0f;
}
}
}
}