- Home /
Question by
brlan10 · Jan 09, 2017 at 04:47 AM ·
overlapsphere
Check what overlapSphere is colliding with
I want overlapSphere to only return true if it's colliding with an object that has collision with the player enabled. Problem is, I need to know which collider it's overlapping with in order to do that. How can I get access to that, if it's even possible?
Comment
You store the colliders into a collider array, then debug.log all the names of the collider's gameobjects
Collider[] hitColliders = Physics.OverlapSphere(center, radius);
foreach(Collider col in hitColliders)
{
Debug.Log(col.gameObject.name);
}
Something to that effect.
This should work, but I run into this error when implementing something like that:
Cannot implicitly convert type 'UnityEngine.Collider2D' to 'UnityEngine.Collider2D[]'
edit: found this nifty function that will allow for an array: Physics2D.OverlapCircleAll