using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Cyber.Util { /// /// Spins the transform at a defined speed. /// public class Spinner : MonoBehaviour { /// /// The axis this spinner spins around. /// public Vector3 Axis = new Vector3(0, 1, 0); /// /// The rounds per minute of the spinning. /// public float RoundsPerMinute = 30; /// /// Whether the spinner is spinning currently. /// public bool Spinning = true; private float CurrentRelativeSpeed = 1f; private void Start() { CurrentRelativeSpeed = Spinning ? 1f : 0f; } private void Update() { CurrentRelativeSpeed = Mathf.Lerp(CurrentRelativeSpeed, Spinning ? 1f : 0f, 20f * Time.deltaTime); transform.localEulerAngles = transform.localEulerAngles + Axis * RoundsPerMinute * CurrentRelativeSpeed * Time.deltaTime; } } }