Last active
June 14, 2025 22:36
-
-
Save dmattox10/0857024c64e95301878ed35f55fb6cb9 to your computer and use it in GitHub Desktop.
Bonus Script to add a compass
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; | |
| [ExecuteInEditMode] | |
| public class CompassCreator : MonoBehaviour | |
| { | |
| public float offset = 3f; | |
| public float cubeSize = 0.25f; | |
| public Color labelColor = Color.white; | |
| void Start() | |
| { | |
| #if UNITY_EDITOR | |
| CreateLabeledCube("N", Vector3.forward * offset); | |
| CreateLabeledCube("E", Vector3.right * offset); | |
| CreateLabeledCube("S", Vector3.back * offset); | |
| CreateLabeledCube("W", Vector3.left * offset); | |
| #endif | |
| } | |
| #if UNITY_EDITOR | |
| void CreateLabeledCube(string label, Vector3 position) | |
| { | |
| GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); | |
| cube.transform.SetParent(transform); | |
| cube.transform.localPosition = position; | |
| cube.transform.localScale = Vector3.one * cubeSize; | |
| // Create a child for the label | |
| GameObject labelObj = new GameObject($"Label_{label}"); | |
| labelObj.transform.SetParent(cube.transform); | |
| labelObj.transform.localPosition = Vector3.up * (cubeSize + 0.1f); | |
| var textMesh = labelObj.AddComponent<TextMesh>(); | |
| textMesh.text = label; | |
| textMesh.color = labelColor; | |
| textMesh.fontSize = 24; | |
| textMesh.anchor = TextAnchor.MiddleCenter; | |
| textMesh.alignment = TextAlignment.Center; | |
| } | |
| #endif | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment