- Home /
Detect certain objects in a certain area
Hi, i have several copies of the same object called 'enemy' on my surroundings, when i click with the mouse somewhere on the ground i'd like to detect which enemys are on the near area of the (RaycastHit)hit.point of the mouse at the moment of the mouse click, just like casting a spell on that location.
So how can i detect which enemys are in that area?
Answer by nixcs2512 · Aug 05, 2013 at 08:23 PM
just a solution :
First take a Raycast from screen to ray.Check Camera.ScreenPointToRay
2 . When you have a hit.point, cast a sphere to get all colliders inside it.Check Physics.OverlapSphere
The first part i had already figured out as you could see in the initial question, the second part was actualy somewhat what i was looking for, it is just a shame that it only has spheres and capssules, it would be awsome if there was a fuction that reacived an object and checked for colisions betwin that object and everything else(f.e. enemys).
if you have "an object"(say A Object), why don't you use OnTriggerEnter for A ? Or simply take the position of A and cast a Sphere(Capsule) and take all hit objects (except A)?
Well, the "A" object doesnt exist like the sphere in 'OverlapSphere' doesnt actualy exists in the scene, the point is actualy to get a list of objects within the area of the same shape of that 'A' object around a certain coordinates. I'll stick to only spheres for now then. Thank you.