c# - 如何多次旋转游戏对象

标签 c# unity3d

尝试使用建议的选项有一个错误 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/

相关文章:

c# - 从类中分解所有依赖项的最简单、最快的方法

c# - 防止实现不是接口(interface)方法的方法

c# - 是否存在 Application.Exit() 不引发 FormClosing 事件的情况?

unity3d - #pragma kernal Main上的语法错误

unity3d - 如何在后处理顶点和片段着色器中计算对象的径向距离

c# - 如何使用表设置模型没有任何主键列

c# - BaseController参数化构造函数

unit-testing - 在 Unity3d 测试脚本中,如何从另一个类调用静态函数?

unity3d - fatal error !系统内存不足!统一3D

unity3d - Linux 上的 UnityHub "Not Enough Space"错误