SanAndreasUnity/Assets/Scripts/Utilities/Rotator.cs

36 lines
711 B
C#
Raw Normal View History

2020-05-31 17:07:22 +00:00
using UnityEngine;
namespace SanAndreasUnity.Utilities
{
public class Rotator : MonoBehaviour {
public Vector3 angles = Vector3.zero;
public bool changeEulers = false;
void Update () {
Vector3 delta = this.angles * Time.deltaTime;
if (delta.sqrMagnitude < float.Epsilon)
return;
if (this.changeEulers) {
Vector3 eulers = this.transform.localEulerAngles;
eulers += delta;
this.transform.localEulerAngles = eulers;
} else {
this.transform.rotation *=
Quaternion.AngleAxis (delta.x, Vector3.right)
* Quaternion.AngleAxis (delta.y, Vector3.up)
* Quaternion.AngleAxis (delta.z, Vector3.forward);
}
}
}
}