How would one go about creating a rolling HP text like Earthbound
I have 100 HP and an enemy deals a blow that causes 35 damage. I want the HP value to count down (99,98,97....65).
I want it to be similar to Earthbound's system as seen here https://youtu.be/nAmBIljqgR8?t=69 See the player "Jeff"'s HP at the 1:11 mark. I am using a plain UI Text as my HP and it is updated in my UpdateUIStats function
I tried creating a Coroutine in which I decrement the player's HP. This coroutine is called within a for loop in my DealDamage function. This loop runs as long as i is less than damageToDeal.
for(int i = 0; i < damageToDeal; i++)
{
StartCoroutine(DamageCounter(target));
}
here is my DamageCounter coroutine:
public IEnumerator DamageCounter(int target)
{
activeBattlers[target].currentHP--;
UpdateUIStats();
yield return new WaitForSeconds(1f);
}
public void UpdateUIStats()
{
for(int i = 0; i < playerName.Length; i++)
{
if(activeBattlers.Count > i)
{
if (activeBattlers[i].isPlayer)
{
BattleChar playerData = activeBattlers[i];
playerName[i].gameObject.SetActive(true);
playerName[i].text = playerData.charName;
playerHP[i].text = Mathf.Clamp(playerData.currentHP, 0, int.MaxValue) + "/" + playerData.maxHP;
playerMP[i].text = Mathf.Clamp(playerData.currentMP, 0, int.MaxValue) + "/" + playerData.maxMP;
}
else
{
playerName[i].gameObject.SetActive(false);
}
}
else
{
playerName[i].gameObject.SetActive(false);
}
}
}
The problem with this code is that it seems to have no effect, HP goes from 100 to 65. I may be way off, this is my first attempt at trying to do this. Any ideas?
Your answer
Follow this Question
Related Questions
How to erase message after 3 seconds 1 Answer
Destroy Problem 2 Answers
Issues with Scrolling Dialogue (repeating characters when printing text) 0 Answers