Created
December 15, 2019 06:56
-
-
Save liveasnotes/e04028b8bd4192955e978e6e02736965 to your computer and use it in GitHub Desktop.
[Unity] 親オブジェクトとの相対位置・回転の固定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
子オブジェクトにアタッチして使う