Files
2023-04-06 09:55:51 +02:00

38 lines
1003 B
C#

using System;
using Station46.Scripts;
using UnityEngine;
namespace Station46.Modules.Hexagon.Scripts
{
/// <summary>
/// The rotator component used by the hexagon module.
/// </summary>
[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<Emission>();
}
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);
}
}
}
}