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.

alt text

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!

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 :slight_smile:

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