尝试使用建议的选项有一个错误 vector3 right is not in its definition 线 transform.Rotate(Vector3.Right
提前谢谢你
using UnityEngine;
using System.Collections;
public class ForwardBack : MonoBehaviour {
// speed variable
public float speed;
public KeyCode pressLeft;
public KeyCode pressRight;
public float rotationSpeed;
// Use this for initialization
void Start () {
speed = 1f;
}
// Update is called once per frame
void Update () {
transform.Translate(0f, speed*Input.GetAxis("Vertical") * Time.deltaTime,0f);
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(Vector3.Right * rotationSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(Vector3.Left * rotationSpeed * Time.deltaTime);
}
}
}
最佳答案
尝试使用 Input.GetKey
而不是 Input.GetKeyDown
Input.GetKeyDown
检测按钮是否被按下,而 Input.GetKey
检查是否连续按下。我想这就是为什么您的圆柱体只转动一次的原因。
关于c# - 如何多次旋转游戏对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36865690/