using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spinner : MonoBehaviour { //Connections private RectTransform RectTrans; //Attributes public float SpinSpeed = 1.5f; public bool InSegments = true; public float SegmentSize = 45f; //Stats protected bool IsAwoken = false; private float CurrentRotation = 0f; //Getter //Delegates //------------------------------------------------------------------------------------------------------------------ //awake, start protected void Awake() { //Already Awoken? if (!IsAwoken) { IsAwoken = true; RectTrans = GetComponent(); } } //************************************************************************************************************ void Update () { CurrentRotation -= 360f * SpinSpeed * Time.deltaTime; if (InSegments) { RectTrans.rotation = Quaternion.Euler(0f, 0f, Mathf.Floor(CurrentRotation / SegmentSize) * SegmentSize); } else { RectTrans.rotation = Quaternion.Euler(0f, 0f, CurrentRotation); } } //************************************************************************************************************ public void SetLoadingPosition(float pos) { //Debug.LogWarning("Spinner: SetLoadingPosition: " + pos); Awake(); if (float.IsNaN(pos)) { RectTrans.rotation = Quaternion.identity; } else { //Debug.LogWarning("Spinner: SetLoadingPos: " + pos); RectTrans.rotation = Quaternion.Euler(0f, 0f, pos * -360f); } } }