|
hi all, i was woundering if there is a way to active a gui object (like a button) when my character get close to it and deactivates when he is far and WITHOUT using colliders (they are just messy and difficult to use, they'll be my last resort). My game is a space so it has to be able to go everywhere aswell here is a copy of my GUI code:
Thank you in advance, Lachee
(comments are locked)
|
|
Use the Pythagorean theorem: SqRoot[(x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2]. This gives you the distance between 2 points in 3D-Space. If dist < trigger radius, then activate button. You might not want to do this every frame... but if you do it every half-second/quarter-second or so it won't affect your frame-rate that much... Example: can you give an example?
Nov 19 '10 at 03:42 AM
Lachee1
I added a quick example. Note that I only stored the player and enemy positions in another variable for ease of coding (it's not necessary); otherwise I'd have to do (transform.position.x - enemy.transform.position.x), etc.
Nov 19 '10 at 01:15 PM
The_r0nin
thank you for helping. I can now use this to advance my gui! (once i debug the previous problem :])
Nov 20 '10 at 10:41 AM
Lachee1
(comments are locked)
|
