I have 2 colliders on my object, one is set to trigger the other one is not. What should I add to my code to select the radius of the trigger collider?
jumpEnablerRadius = player.transform.GetComponent<CircleCollider2D>().radius;
This code returns the radius of the collider that I use for physics, and therefore is not a trigger. I tried using an if statement with .isTrigger , but I can’t get it to work.
I also tried using GetComponents, but I can’t seem to extract the trigger out of the array it returns, I have very bad understanding of loops.
Edit:
Simon really nailed it. Here’s the adapted code for people who stumble on this question.
CircleCollider2D[] colliders = player.transform.GetComponents<CircleCollider2D>();
foreach (CircleCollider2D collider in colliders)
{
if (collider.isTrigger) {
jumpEnablerRadius = collider.radius;
Debug.Log ("Jumper radius set" + jumpEnablerRadius.ToString());
}
}