- Home /
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?
Answer by MithosAnnar · Feb 28, 2012 at 12:02 PM
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!
Answer by Berenger · Feb 27, 2012 at 11:20 PM
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.
its not a healthbar above the enemy. its everything including the portrait and name that comes up when an enemy is targeted like in wow.
Answer by Meltdown · Feb 28, 2012 at 09:45 AM
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.
Your answer
Follow this Question
Related Questions
Game Texture - Always Face Camera 1 Answer
transform.position as variable to lock object 0 Answers
Finding the limits of transform coordinates 1 Answer
How to use transform.position? 2 Answers
change bar position 1 Answer