Unityでは、コントロールオブジェクトはY軸に沿ってカスタム速度で90度回転し(カスタマイズも可能)、停止してから元の位置に戻ります。



Unity Control Object Is Rotated 90 Degrees Along Y Axis Custom Speed



1.次のようにY軸に沿って回転するオブジェクトを制御する必要があります。



2.次のようにオブジェクトの回転を制御するスクリプトを記述します。

using UnityEngine using System.Collections public class Test_CycleRoate : MonoBehaviour { Public int rotateAngle=90 //rotation angle Public int rotateSpeed=2 //rotation speed Private bool isOpen=false //Open the exhaust door Private bool isClose=false //close the damper // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(isOpen) { RotateXOpen(rotateAngle) } if(isClose&&isOpen==false) { RotateXClose() } } /// /// Open the damper /// public void OpenEnterWindDoor() { isOpen=true Debug.Log('1111') } /// /// Close the intake damper /// public void CloseEnterWindDoor() { isClose = true Debug.Log('222') } /// /// Rotates the X open. /// /// Curent rotate angle. (The default range is 0-90 degrees) private void RotateXOpen(int CurentRotateAngleY=90) { if (CurentRotateAngleY > 0 && CurentRotateAngleY =CurentRotateAngleY) { isOpen=!isOpen Debug.Log(isOpen) } } else { Debug.Log(GetType()+'/CtrlGameObjectRoate()/Set the rotation angle not in the range of 0-90 degrees, please re-enter!!!') } } /// /// Rotates the X close. /// private void RotateXClose() { Quaternion target=Quaternion.Euler(90,0,0) transform.rotation=Quaternion.RotateTowards(transform.rotation,target,rotateSpeed) if(transform.rotation.eulerAngles.y<=0) { isClose=!isClose Debug.Log(isClose) } } }

3.制御する必要のあるオブジェクトに制御スクリプトを追加し、ボタンに制御メソッドを指定します。



第四に、効果を達成するために対応するボタンを実行します