using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpinVert : MonoBehaviour { [Header("\tSpin on axis")] [SerializeField] public bool X = false; [SerializeField] public bool Y = false; [SerializeField] public bool Z = false; [Header("\tController")] [Tooltip("When this is true, it is spinning")] [SerializeField] private bool Spin = false; [Tooltip("How fast we are spinning")] [SerializeField] private float Speed = 100f; [Tooltip("What angle do we stop at")] [SerializeField] private float StopAt = 90f; [Header("\tStarting Positions")] [SerializeField] private float RotX = 0f; [SerializeField] private float RotY = 0f; [SerializeField] private float RotZ = 0f; void Start() { /* Vector3 temp = transform.rotation.eulerAngles; temp.x = RotX; temp.y = RotY; temp.z = RotZ; transform.rotation = Quaternion.Euler(temp); */ } // Update is called once per frame void Update() { if (Spin) { Vector3 temp = transform.rotation.eulerAngles; if (X) { transform.Rotate(Speed * Time.deltaTime, 0f, 0f, Space.Self); DoContinue(temp.x); } if (Y) { transform.Rotate(0f, Speed * Time.deltaTime, 0f, Space.Self); DoContinue(temp.y); } if (Z) { transform.Rotate(0f, 0f, Speed * Time.deltaTime, Space.Self); DoContinue(temp.z); } } } public void StartSpinning(string Axis = "none", float fSpeed = 100f, float fStopAt = 80f) { Spin = true; Speed = fSpeed; StopAt = fStopAt; if (Axis == "X" || Axis == "x") X = true; if (Axis == "Y" || Axis == "y") Y = true; if (Axis == "Z" || Axis == "z") Z = true; } private void DoContinue(float i) { if (i > StopAt) Spin = false; } public void ResetRotation() { Vector3 temp = transform.rotation.eulerAngles; if (X) temp.x = RotX; if (Y) temp.y = RotY; if (Z) temp.z = RotZ; transform.rotation = Quaternion.Euler(temp); } }