【发布时间】:2019-10-29 14:48:41
【问题描述】:
当按住 D 向上和 W 向下时,我需要使对象在 z 轴上旋转,但限制了两个方向的旋转,使用下面提供的代码我设法使对象在按下时旋转,但确实如此当达到我的变量设置的 2 个限制中的任何一个时,不会停止旋转。
我是编码领域的新手,希望您能帮助我解决和理解我的问题。提前感谢您的宝贵时间。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GyroDiscControls : MonoBehaviour{
public GameObject AltNeedleBright;
public float MaxAltNeedleRotation = -65f;
public float MinAltNeedleRotation = 135f ;
public void update (){
if (Input.GetAxisRaw("Vertical") > 0 &
AltNeedleBright.transform.rotation.z > MaxAltNeedleRotation)
{
AltNeedleBright.transform.Rotate(0f, 0f, +15f * Time.deltaTime);
}
if (Input.GetAxisRaw("Vertical") < 0 &
AltNeedleBright.transform.rotation.z < MinAltNeedleRotation)
{
AltNeedleBright.transform.Rotate(0f, 0f, -15f * Time.deltaTime);
}
}
【问题讨论】:
-
你的意思是如何在两个角度之间夹住一个对象的旋转。