- Home /
Question by
jason0202 · Feb 14, 2012 at 10:03 AM ·
worldtoscreenpointrocketguibox
GUI Box to draw Target Lock Icon
Hi,
I planned to use OnGUI function to draw "Target Lock" icon on incoming rockets for FPS game.
this is just an example
Requirement:
1) able to expand in size if the rocket comes near
2) able to track rocket using WorldToScreenPoint function
Any idea on how to do it? Thanks!
Comment
Answer by Ben Ezard · Jun 16, 2012 at 09:07 PM
You can increase the size of the target lock icon by using
var size = 1/Vector3.Distance(player.transform.position, enemy.transform.position)It will now increase as the enemy gets closer and decrease as it gets further away
For the tracking bit, use:
var position = Data.cam.camera.WorldToScreenPoint (enemies[e].position); position.y = Screen.height - position.y; GUI.DrawTexture(Rect((position.x - (size/2)), (position.y - (size/2)), size, targetSize), texture);
And there you have it :)
P.S. you'll probably need to multiply the 'size' variable by a number so that the target lock icon doesn't increase or decrease too quickly
Your answer
Follow this Question
Related Questions
Converting world coordinates to screen coordinates 1 Answer
Cloud recognition in Vuforia 0 Answers
Need help with Animations 1 Answer
Mid point of a object 1 Answer