Skip to content

Instantly share code, notes, and snippets.

@liveasnotes
Created December 15, 2019 06:56
Show Gist options
  • Select an option

  • Save liveasnotes/e04028b8bd4192955e978e6e02736965 to your computer and use it in GitHub Desktop.

Select an option

Save liveasnotes/e04028b8bd4192955e978e6e02736965 to your computer and use it in GitHub Desktop.
[Unity] 親オブジェクトとの相対位置・回転の固定
using UnityEngine;
public class FixPhysicalState : MonoBehaviour
{
public bool fixPosition = true;
public bool fixRotation = true;
Vector3 own_initialRot;
Vector3 own_initialLocalPos;
Vector3 parent_pos;
void Awake()
{
own_initialRot = this.transform.eulerAngles;
own_initialLocalPos = this.transform.localPosition;
}
void Update()
{
if (fixPosition)
{
parent_pos = this.transform.parent.position;
this.transform.position = parent_pos + own_initialLocalPos;
}
if (fixRotation)
{
this.transform.eulerAngles = own_initialRot;
}
}
}
@liveasnotes
Copy link
Author

子オブジェクトにアタッチして使う

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment