Is there a way to find out what type of collider an object has?

Is there a way to find out what type of collider (box, sphere, mesh) an object has?

I know I can check for each type individually, but I need to dynamically change collider parameters on several different types, so it would be nice to do it in a more generic manner

thanks

You can simply ask:

C#

if(collider.GetType() == typeof(MeshCollider)) print("mesh");

And JS

if(collider.GetType() == MeshCollider) print("mesh");

Hope that helps

==

You can do .name if you are looking for it’s name.

GetType() will return the specific type of collider.

For Example, if your GameObject contains a Capsule Colldier:

Collider collider = target.GetComponent<Collider>();
Debug.Log(collider.GetType().ToString());

//will return UnityEngine.CapsuleCollider