Created
November 8, 2024 11:14
-
-
Save unitycoder/cba039421746aa10859fa2756ff4c77e to your computer and use it in GitHub Desktop.
Debug draw sphere box script
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
| // https://discussions.unity.com/t/debug-draw-sphere-script/1550055 | |
| using System.Collections; | |
| using UnityEngine; | |
| public static class DebugUtilities | |
| { | |
| /// <summary> | |
| /// Draw primitive forms like capsule, cubes ecc... for a N time in a location. | |
| /// (similar to Debug.DrawRay) | |
| /// </summary> | |
| public static void DrawPrimitive(Vector3 position, float scale, PrimitiveType primitiveType, Color color, float time = 1f) | |
| { | |
| #if UNITY_EDITOR | |
| GameObject sphere = GameObject.CreatePrimitive(primitiveType); | |
| sphere.transform.localScale = new Vector3(scale, scale, scale); | |
| sphere.transform.position = position; | |
| sphere.GetComponent<Renderer>().material.color = color; | |
| sphere.AddComponent<DestroySelf>(); | |
| #endif | |
| } | |
| } | |
| public class DestroySelf : MonoBehaviour | |
| { | |
| public void Start() | |
| { | |
| StartCoroutine(SelfDestruct()); | |
| } | |
| private IEnumerator SelfDestruct() | |
| { | |
| yield return new WaitForSeconds(5f); | |
| Destroy(gameObject); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment