Hello Everyone.
In the UnitWorld UI Course, if you want to add numerical information according Hit Point left, just apply the few following modifications to your game.
To Start, Add a new UI/TextMeshPro and call it HitPoints (for exemple):
Reset the values of position and Height and Widht:
Put any value you want in the text for exemple 10, to see the update when the game will start.
as for the Action Point TextMeshPro choose the same setting (underlined in red for me)
Adjust the Font size to your own Interface.
Then Open your UnitWorldUI Script and add a serialisedField for your HitPoints text:
[SerializeField] private TextMeshProUGUI healthPointsText;
Save, return to unity and add opening the Unit Prefab your HitPointText by dragging it to the right field.
Then in your UnitWorldUI Script add a new method to display the realtime HitPoints left:
private void UpdateHealthPointsText()
{
healthPointsText.text = (healthSystem.GetHealthNormalised()*100).ToString();
}
We multiply by 100 because the method who inform the game of the Lefting point is normalised, so between 0 and 1.
If you don’t multiply by Hundred you will only display 1 until the guy die.
Second bonus, By multiply by 100 you will be sure that you will always display an integer number whatever the damage (in integer) your weapon will do.
Then in the Start method add the new method (UpdateHealthPointsText()) to be able to update the HitPoint value beginning the game
private void Start()
{
Unit.onAnyActionPointsChanged += Unit_onAnyActionPointsChanged;
healthSystem.OnDamage += healthSystem_OnDamage;
UpdateActionPointsText();
UpdateHealthBar();
UpdateHealthPointsText();
}
And in the healthSystem_OnDamage() method to update the Hitpoint avec a Damage.
private void healthSystem_OnDamage(object sender, EventArgs e)
{
UpdateHealthBar();
UpdateHealthPointsText();
}
Now you will have the numerical Hit Points lefting in your Health bar according to the health Points lefting
For me before I start, the whole units display ten points:
And when I start, they have their 100 points, according to the value we have entered in the script:
And when you will shoot an enemy unit, its own bar will update in the same Time the red bar will decrease:
Hope it helps.
Have a nice day.
François