2023-03-28 13:16:30 -04:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class SpinVert : MonoBehaviour
|
|
|
|
{
|
2023-05-05 23:02:18 -04:00
|
|
|
[Header("\tSpin on axis")]
|
|
|
|
[SerializeField] public bool X = false;
|
|
|
|
[SerializeField] public bool Y = false;
|
|
|
|
[SerializeField] public bool Z = false;
|
2023-04-26 01:28:58 -04:00
|
|
|
|
2023-05-05 23:02:18 -04:00
|
|
|
[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;
|
2023-04-30 00:04:18 -04:00
|
|
|
|
2023-05-05 23:02:18 -04:00
|
|
|
[Header("\tStarting Positions")]
|
|
|
|
[SerializeField] private float RotX = 0f;
|
|
|
|
[SerializeField] private float RotY = 0f;
|
|
|
|
[SerializeField] private float RotZ = 0f;
|
2023-04-30 00:04:18 -04:00
|
|
|
|
2023-05-05 23:02:18 -04:00
|
|
|
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
|
|
|
|
2023-05-05 23:02:18 -04:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-26 01:28:58 -04:00
|
|
|
|
2023-05-05 23:02:18 -04:00
|
|
|
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;
|
|
|
|
}
|
2023-04-30 00:04:18 -04:00
|
|
|
|
2023-05-05 23:02:18 -04:00
|
|
|
private void DoContinue(float i) {
|
|
|
|
if (i > StopAt)
|
|
|
|
Spin = false;
|
|
|
|
}
|
2023-04-30 00:04:18 -04:00
|
|
|
|
2023-05-05 23:02:18 -04:00
|
|
|
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);
|
|
|
|
}
|
2023-04-26 01:28:58 -04:00
|
|
|
}
|