Homebound / Scripts / RotationHandler.cs
RotationHandler.cs
Raw
using UnityEngine;

public class RotationHandler : MonoBehaviour
{
    [Header("Values")]
    [SerializeField] Vector3 rotationAmount; // Reference for how much rotation should occur in what direction
    [SerializeField] float rotationSpeed; // Reference for how quick the rotation should occur, essentially the magnitude for the rotation amount
    [SerializeField] bool menuObject; // Trigger for if the object should continue to rotate while player is on a screen

    void FixedUpdate()
    {
        // While the game is not paused or if the item is labeled as an object that should be spinning while paused the item with this component will rotate
        if (!MainMenu.IsPaused || menuObject)
            RotateGameObject();
    }

    /// <summary>
    /// Rotates the object based on rotationSpeed and time
    /// </summary>
    void RotateGameObject() => transform.Rotate(rotationSpeed * Time.deltaTime * rotationAmount);
}