Created
October 11, 2015 16:18
-
-
Save Naphier/848009e6155c6a8906f7 to your computer and use it in GitHub Desktop.
Shows all active colliders in a scene with different color for triggers vs colliders.
This file contains 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 ShowColliders : MonoBehaviour | |
{ | |
public enum collidertype | |
{ All, TriggersOnly, CollidersOnly, None} | |
public collidertype show = collidertype.All; | |
public Color colliderColor = Color.yellow; | |
public Color triggerColor = Color.blue; | |
void OnDrawGizmos() | |
{ | |
if (show == collidertype.None) | |
return; | |
GameObject[] all = GameObject.FindObjectsOfType<GameObject>(); | |
for (int i = 0; i < all.Length; i++) | |
{ | |
if (all[i].activeInHierarchy) | |
{ | |
switch (show) | |
{ | |
case collidertype.All: | |
DrawCollider(all[i]); | |
DrawTrigger(all[i]); | |
break; | |
case collidertype.TriggersOnly: | |
DrawTrigger(all[i]); | |
break; | |
case collidertype.CollidersOnly: | |
DrawCollider(all[i]); | |
break; | |
case collidertype.None: | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
} | |
void DrawCollider(GameObject go) | |
{ | |
Collider _collider = go.GetComponent<Collider>(); | |
if (_collider == null) | |
return; | |
if (_collider.isTrigger) | |
return; | |
Gizmos.color = colliderColor; | |
Gizmos.DrawWireCube(_collider.bounds.center, _collider.bounds.size); | |
} | |
void DrawTrigger(GameObject go) | |
{ | |
Collider _collider = go.GetComponent<Collider>(); | |
if (_collider == null) | |
return; | |
if (!_collider.isTrigger) | |
return; | |
Gizmos.color = triggerColor; | |
Gizmos.DrawWireCube(_collider.bounds.center, _collider.bounds.size); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment