- Home /
[SOLVED] Object detection inside a GUI area
Hi guys, today i'm here with a new problem for you!!! YEAH !!! Basically what i'm trying to do is to detect if an object is inside a GUI area...well...a circle crosshair. Image to explain:
So when an enemy is inside of this crosshair a target-lock texture shows up and follows the enemy (this part of the script is already done, so you can skip it)
I hope in someone that can help me out and thanks in advance Bye ;)
Dude, if a target-lock texture shows up then your scripts is detecting when the enemy is inside! please post your code
Answer by Ejlersen · Aug 20, 2013 at 08:24 PM
One way of doing it:
Use WorldToScreenPoint using the objects position to get the point on screen.
Calculate distance from crosshair center to point on screen.
If this distance is less than your crosshair radius, then its inside.
thanks for the answer, but how can i get the distance between two screen points? I'm stuck at this point :S
Ok guys i've got it. Now everything works as i was expecting. You guys helped me a lot and thanks for this. :D Thanks another time and see you soon...i guess ;) !