during this week I mainly worked on the GUI
aspect of my turn based strategy game, for example floating Health Bars for my units, backgrounds for the
health bar, text for when an attack
misses and an icon for the poison status when a unit becomes poisoned. this is
all handled by setting the screen position to MainCamera.WorldToScreenPoint and
the position of the transform holding the script. a new rect is created at the
screen position and tweaked in order to fit the right position for example this
is the rectangle for my Health Bar:
Rect rect = new Rect (ScreenPos.x - 50,
ScreenPos.y - 30, 100 / (100 / PlayerHealth), 15);
therectangle is also affected by the player's
Health which causes it to reduced size the lower the players health becomes. A
GUI.Box is created using the information shown in the rectangle but using its
own GUIStyle variable allowing textures to be easily added to the health bar
script.
I discovered how to created these floating GUI
textures from this answer in Unity answers which I recommend you have a look at
if you want to add a floating health bar to your game:
I also recommend reading the Unity Scripting API
for camera.ScreenToWorldPoint which is linked here:
If you have any feedback about this post please
let me know

No comments:
Post a Comment