- Home /
The question is answered, right answer was accepted
How can I access collider's game objects?
Collider [] collidedObjects = Physics.OverlapSphere(transform.position,0.54f);
I'm using this to return all colliders that's in that area. But I need to access their game objects. Any ideas?
Edit : Don't tell me to use SphereCast because that won't work in my case since I need isTriggers active on my game objects.
You're mixing your ter$$anonymous$$ology quite a bit here.
A) SphereCast will only pick up colliders, so it would be totally redundant to perform one when you already have an array of colliders. B) GameObjects don't have an isTrigger flag, only colliders do.
Answer by YoungDeveloper · Jan 19, 2014 at 08:02 PM
Like this ?
for(int i = 0; i < collidedObjects.Length; i++){
collidedObjects[i].gameObject. ..
}
Doesn't that return the game object that hits the collider?
It returns the game object of the collider in the array at index i.
It returns each coliders gameObject i believe, isn't that what you wanted? By the way, you can test it pretty easy what returns what you know
Sorry, I'm all confused here. So what does return hit object?
What you mean by hit object ?
What you do here is, you save colliders in array, through collider you can access it's gameobject. Nothing complicated here.
Follow this Question
Related Questions
Aura/AOE Problem 2 Answers
how to make physics.OverlapSphere check multiple colliders? 1 Answer
Random results with physics.OverlapSphere and AOE attacks 0 Answers
Collider Array showing up empty,No Colliders showing up in my array 0 Answers
OverlapSphere picking colliders that are not inside 0 Answers