using System; using Station46.Scripts; using UnityEngine; namespace Station46.Modules.Hexagon.Scripts { /// /// The rotator component used by the hexagon module. /// [RequireComponent(typeof(Emission))] public class Rotator : MonoBehaviour { [Tooltip("The angle this rotator should rotate towards.")] [Range(0, 359)] public int angle; [Tooltip("How quickly to rotate towards the target angle.")] [Range(0, 1)] public float speed; public Emission Emission { get; private set; } private void Awake() { Emission = GetComponent(); } private void Update() { angle %= 360; var angleDifference = angle - transform.localEulerAngles.y; if (Math.Abs(angleDifference) >= 0.1) { transform.Rotate(0, angleDifference*Mathf.Pow(speed, 2), 0, Space.Self); } } } }