|
Hello, I am new to Unity so I've been using several tutorials to try different things I used the Health Bar tutorial of http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial and made some modifications to create mine. And I want to know: is it possible to make a GUI.Box Rectangle follow a character's position so that it hovers above its head? I tried using the ObjectLabel script http://www.unifycommunity.com/wiki/index.php?title=ObjectLabel but this only works for GUI Text/Textures I think it could be done if I modify the z position of the rectangle to follow the camera but I have tried several things and I can't make it work. EDIT: I added the corrected script to help if someone had the same problem as me: using UnityEngine; using System.Collections; public class PlayerHealth : MonoBehaviour {
(comments are locked)
|
|
One method you could try would be to use Camera.WorldToScreenPoint() to compute a screen-space point corresponding to the character's position. If you unproject a point at the top of the character's head and then offset the GUI element vertically from that point, you should end up with a GUI element that appears to float above the character. Thank you for your answer, I'm still trying to get this to work but now I know what I'm supposed to be doing.
Sep 06 '10 at 07:48 PM
Jes
I tried again today and it worked! WorldToScreenPoint was what I needed and I updated the script to help others with the same problem.
Sep 09 '10 at 10:17 PM
Jes
(comments are locked)
|
|
Ty I solved this code is working for me :D
using UnityEngine; using System.Collections; public class EnemyHealth : MonoBehaviour { public int maxHealth=100; public int curHealth=50; public Vector3 screenPosition;
}
(comments are locked)
|
|
This helped me tremendously, thank you. Every tutorial and youtube video I found was for a fixed healthbar, and not a dynamic one. This works great.
(comments are locked)
|
