SnapRotate.cs
unknown
csharp
3 years ago
841 B
21
Indexable
using UnityEngine;
[ExecuteInEditMode]
public class SnapRotate : MonoBehaviour
{
public Discrete2DRotation Pitch { get; private set; }
public Discrete2DRotation Yaw { get; private set; }
public Discrete2DRotation Roll { get; private set; }
public SnapRotate()
{
Pitch = new Discrete2DRotation();
Yaw = new Discrete2DRotation();
Roll = new Discrete2DRotation();
}
private void Update()
{
ApplyRotation();
}
private void OnValidate()
{
ApplyRotation();
}
private void ApplyRotation()
{
// Reset the rotation
transform.rotation = Quaternion.identity;
// Apply pitch, yaw, and roll rotations sequentially
transform.Rotate(Vector3.right, Pitch.RotationAngle, Space.Self);
transform.Rotate(Vector3.up, Yaw.RotationAngle, Space.Self);
transform.Rotate(Vector3.forward, Roll.RotationAngle, Space.Self);
}
}Editor is loading...