46 lines
884 B
C#
46 lines
884 B
C#
using UnityEngine;
|
|
|
|
public class RotateUI : MonoBehaviour
|
|
{
|
|
[Header("Rotation Settings")]
|
|
[SerializeField] private float rotateSpeed = 30f;
|
|
[SerializeField] private bool clockwise = true;
|
|
[SerializeField] private bool playOnStart = true;
|
|
|
|
private bool isRotating;
|
|
|
|
private void Awake()
|
|
{
|
|
isRotating = playOnStart;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!isRotating)
|
|
return;
|
|
|
|
float dir = clockwise ? -1f : 1f;
|
|
|
|
transform.Rotate(0f, 0f, dir * rotateSpeed * Time.deltaTime, Space.Self);
|
|
}
|
|
|
|
public void StartRotate()
|
|
{
|
|
isRotating = true;
|
|
}
|
|
|
|
public void StopRotate()
|
|
{
|
|
isRotating = false;
|
|
}
|
|
|
|
public void SetClockwise(bool value)
|
|
{
|
|
clockwise = value;
|
|
}
|
|
|
|
public void ResetRotation()
|
|
{
|
|
transform.localEulerAngles = Vector3.zero;
|
|
}
|
|
} |