Skip to content

Instantly share code, notes, and snippets.

@ChigusaApp
Created September 9, 2019 05:35
using UnityEngine;
namespace Chigusa
{
/// <summary>
/// 回転を打ち消す
/// (スプライトなどで常に正面を向かせるなど)
/// </summary>
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class RotationCancel : MonoBehaviour
{
[Tooltip("Edit中にも反映させる")]
public bool executeInEditMode = true;
/// <summary>
/// Update
/// </summary>
void Update()
{
#if UNITY_EDITOR
if (!executeInEditMode)
return;
#endif
// 打ち消す
if (transform.parent)
transform.localRotation = Quaternion.Inverse(transform.parent.rotation);
else
transform.localRotation = Quaternion.identity;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment