Created
April 16, 2025 02:21
-
-
Save noahjames404/f14a17fd8d6415eee289726970ed36d5 to your computer and use it in GitHub Desktop.
Centralize the game object pivot in 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 Sirenix.OdinInspector; | |
| using UnityEngine; | |
| namespace maphatar.civsim | |
| { | |
| public class GetCenterBounds : MonoBehaviour | |
| { | |
| [SerializeField, ReadOnly] | |
| Vector3 center; | |
| [SerializeField] | |
| GameObject reference; | |
| [Button] | |
| public void ComputeBoundsAndCentralized() | |
| { | |
| center = reference.transform.TransformPoint(reference.GetComponent<BoxCollider>().center); | |
| var obj = new GameObject(); | |
| obj.transform.position = center; | |
| transform.SetParent(obj.transform); | |
| obj.name = name + " (container)"; | |
| } | |
| private void OnDrawGizmosSelected() | |
| { | |
| Gizmos.color = Color.yellow; | |
| Gizmos.DrawSphere(center,1); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment