- Home /
How to get the right Collider component?
I have a box with two Box Colliders attached: one of them acts as a trigger, and the other one acts as a physic collider. I want to access the non-trigger collider, but I can't figure out how to, as both have the same name.
Any ideas?
Answer by PAEvenson · Jun 06, 2014 at 02:03 PM
You could have a script store the references to the two components like so:
public BoxColliderReferences: MonoBehaviour
{
#region Assign in Inspector
public BoxCollider nonTriggerCollider;
public BoxCollider triggerCollider;
#endregion
}
Make sure you assign both of them inside the inspector. To access the Colliders
BoxColliderReferences theColliders = GameObject.Find("MyObject").GetComponent<BoxColliderReferences>();
if(theColliders.nonTriggerCollider.isTrigger == false)
{
Debug.Log("We are not a trigger");
}
Answer by AlucardJay · Jun 06, 2014 at 02:58 PM
Use GetComponents, then check each for each collider found if it is trigger.
Your answer
Follow this Question
Related Questions
Collider.enabled working differently from inspector? 1 Answer
Can't click gameobject when over another trigger? 1 Answer
Triggering platform animation on colliding with Button 0 Answers
Use trigger with player but have a collider with everything else? 3 Answers
How do you go from one scene, to another, then a third and back again ? 0 Answers