- Home /
Collider ignore raycast
I have an object with a box collider and a sphere collider, I use them both in scripts, but I'm trying to find a way to make the sphere collider ignore clicks without disabling it. Any ideas? Thanks!
Answer by highpockets · Aug 17, 2020 at 08:21 PM
From your question, I understand that you have the box collider and the sphere collider on a single game object. Do you not think it would be best to have each of these colliders on separate game objects? I ask this because you can have each collider on a separate layer if they are on different game objects and do a layer mask to ignore the specific layer:
LayerMask mask = ~(1 << 15 ); //Ignore layer 15
Otherwise, if you must have both of the colliders on the same object for some reason, you would have to do a check to see if the hit collider is a sphere or box collider:
if (GetComponent<Collider> ().GetType () == typeof(SphereCollider))
{
//sphere
}
if (GetComponent<Collider> ().GetType () == typeof(BoxCollider))
{
//box
}
In the game I'm making, I have an attack radius around a game object, which is the sphere collider. But I'm trying to make the object clickable with the box collider. They are both on the same object. When I click, since the sphere is larger, I can't hit the box. Separating the layers sounds like a great idea, but can the game object still access the detection radius from the sphere collider?
One object should be the parent of the other, each with separate colliders. By code you can access all collision and trigger enters from either of the colliders yes