Firstborn/Assets/Scripts/SpinVert.cs
Schaken-Mods 774d18a99d 5/18/2023 Update
made most of the game Moddable. There is an in editor tool to make the mods and set them all up, and im making an external tool that will show your mods, lets you edit any information and it will pack it up and upload it. currently working on the uploading. Next I will make the game able to download and install. - Fuck Nexus.
2023-05-18 20:28:45 -05:00

85 lines
1.9 KiB
C#

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 (999 cancels this)")]
[SerializeField] private float StopAt = 999f;
[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 (StopAt == 999)
return;
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);
}
}