Skip to content

Instantly share code, notes, and snippets.

@Naphier
Created October 11, 2015 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naphier/848009e6155c6a8906f7 to your computer and use it in GitHub Desktop.
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.
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