lock GUITexture on the screen at specific co - ordinates

Hello…

I have redone my game entirely without the use of OnGUI, (which was causing a lot of problems for me).

But now that I am not using OnGUI I have had to put the functionality into my GUI manually.

The issue I have is this…

my GUI is attached to my enemy, when my enemy follows the player the GUI moves with it (across and off the screen).

I have tried setting the positions in - code, but I feel this is very inefficient (especially in the Update function).

I would just like to know how this can be corrected properly. Maybe I can lock it somehow?

If you want the GUITexture to follow the character nicely, use WorldToViewportPoint instead of parenting. The position is in viewport space (0,0 => 1,1), when the parenting modify it in world space.

Attach your GUI to your camera. When you click on the enemy, pass in your enemy information to your camera GUI script.

Alternatively what I do for my GUI is create a second orthographic camera with a higher depth than my main camera, and add a few 2 triangle planes in the right position and put textures/text/bars on them.

You will also need to do some tweaking based on the aspect ratio of the user’s screen so make sure to test and adjust the GUI accordingly.

Ok, I finally fixed the problem.

The solution was to make an empty GameObject and make the GUI elements a child of it and then instantiate it with the enemy.

Thanks for the help!