2023-03-28 13:16:30 -04:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class SpinVert : MonoBehaviour
|
|
|
|
{
|
2023-04-30 00:04:18 -04:00
|
|
|
[Header("\tSpin on axis")]
|
2023-04-26 01:28:58 -04:00
|
|
|
[SerializeField] public bool X = false;
|
|
|
|
[SerializeField] public bool Y = false;
|
|
|
|
[SerializeField] public bool Z = false;
|
|
|
|
|
2023-04-30 00:04:18 -04:00
|
|
|
[Header("\tController")]
|
|
|
|
[Tooltip("When this is true, it is spinning")]
|
|
|
|
[SerializeField] private bool Spin = false;
|
|
|
|
[Tooltip("How fast we are spinning")]
|
2023-04-26 01:28:58 -04:00
|
|
|
[SerializeField] private float Speed = 100f;
|
2023-04-30 00:04:18 -04:00
|
|
|
[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);
|
|
|
|
}
|
2023-03-28 13:16:30 -04:00
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2023-04-26 01:28:58 -04:00
|
|
|
if (Spin) {
|
2023-04-30 00:04:18 -04:00
|
|
|
|
|
|
|
Vector3 temp = transform.rotation.eulerAngles;
|
2023-04-26 01:28:58 -04:00
|
|
|
if (X) {
|
|
|
|
transform.Rotate(Speed * Time.deltaTime, 0f, 0f, Space.Self);
|
2023-04-30 00:04:18 -04:00
|
|
|
DoContinue(temp.x);
|
2023-04-26 01:28:58 -04:00
|
|
|
}
|
|
|
|
if (Y) {
|
|
|
|
transform.Rotate(0f, Speed * Time.deltaTime, 0f, Space.Self);
|
2023-04-30 00:04:18 -04:00
|
|
|
DoContinue(temp.y);
|
2023-04-26 01:28:58 -04:00
|
|
|
}
|
|
|
|
if (Z) {
|
|
|
|
transform.Rotate(0f, 0f, Speed * Time.deltaTime, Space.Self);
|
2023-04-30 00:04:18 -04:00
|
|
|
DoContinue(temp.z);
|
2023-04-26 01:28:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-30 00:04:18 -04:00
|
|
|
public void StartSpinning(string Axis = "none", float fSpeed = 100f, float fStopAt = 80f) {
|
2023-04-26 01:28:58 -04:00
|
|
|
Spin = true;
|
2023-04-30 00:04:18 -04:00
|
|
|
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;
|
|
|
|
temp.x = RotX;
|
|
|
|
temp.y = RotY;
|
|
|
|
temp.z = RotZ;
|
|
|
|
transform.rotation = Quaternion.Euler(temp);
|
2023-03-28 13:16:30 -04:00
|
|
|
}
|
2023-04-26 01:28:58 -04:00
|
|
|
}
|