using UnityEngine; public class Hamilton1843 : MonoBehaviour //★哈密爾頓1843 { public enum TurnStyle //▲旋轉風格 { None, //----------------△無旋轉 Euler, //---------------△尤拉角 LookRotation, //--------△注視旋轉 AngleAxis, //-----------△角度軸 FromToRotation, //------△旋轉到 } public TurnStyle turnStyle; //---------●旋轉風格 public bool isInverse = false; //------●旋轉朝向取逆判定 void Update () {//■更新■ InputDetection(); //模糊輸入檢測,進行使用者測試輸入判定 Quaternion rotation = new Quaternion(); //四元數角度快取 switch (turnStyle) //根據旋轉風格判定 { case TurnStyle.None://----------------△無旋轉 rotation = Quaternion.identity; break; case TurnStyle.Euler://---------------△尤拉角 rotation = Quaternion.Euler(-90, 0, 0); break; case TurnStyle.LookRotation://--------△注視旋轉 rotation = Quaternion.LookRotation(Vector3.up, Vector3.up); break; case TurnStyle.AngleAxis://-----------△角度軸 rotation = Quaternion.AngleAxis(-90, Vector3.right); break; case TurnStyle.FromToRotation://------△同向 rotation = Quaternion.FromToRotation(Vector3.up, Vector3.back); break; } //應用旋轉,並順便判定順逆 transform.rotation = isInverse ? Quaternion.Inverse(rotation) : rotation; } void InputDetection() {//■模糊輸入檢測■ if (Input.inputString != "") //如果有輸入 { char c = Input.inputString[0]; //獲取輸入的首字元 if (c >= 48 && c <= 57) //如果按下的是 0~9 { int i = int.Parse(Input.inputString); //字串轉整數 if (i >= 0 && i <= 4) //如果按下的是 0~4 { turnStyle = (TurnStyle)i; //強轉輸入為旋轉風格 } } else if (c == 32) //如果按下的是 空格鍵 { isInverse = !isInverse; //切換取反 } } } }