Skip to main content
added 136 characters in body
Source Link

Currently working on an overhead display of the health bar and ran into this problem and I cannot seem to figure out why its not working correctly. When the player has less than entity.health.max the scale is set to 0 instead of the calculated percent.

Code:

private void SetHealth(int amount)
{
  currentHealth = amount;
  float displayedHealth = currentHealth / entity.health.max;
  healthBar.transform.localScale = new Vector3(displayedHealth, 1, 1);
}

I also tried the following with the same results

float displayedHealth = Mathf.Lerp(0, 1, currentHealth / entity.health.max);

Currently working on an overhead display of the health bar and ran into this problem and I cannot seem to figure out why its not working correctly. When the player has less than entity.health.max the scale is set to 0 instead of the calculated percent.

Code:

private void SetHealth(int amount)
{
  currentHealth = amount;
  float displayedHealth = currentHealth / entity.health.max;
  healthBar.transform.localScale = new Vector3(displayedHealth, 1, 1);
}

Currently working on an overhead display of the health bar and ran into this problem and I cannot seem to figure out why its not working correctly. When the player has less than entity.health.max the scale is set to 0 instead of the calculated percent.

Code:

private void SetHealth(int amount)
{
  currentHealth = amount;
  float displayedHealth = currentHealth / entity.health.max;
  healthBar.transform.localScale = new Vector3(displayedHealth, 1, 1);
}

I also tried the following with the same results

float displayedHealth = Mathf.Lerp(0, 1, currentHealth / entity.health.max);
Source Link

Floating Health Bar Not Displaying Correctly

Currently working on an overhead display of the health bar and ran into this problem and I cannot seem to figure out why its not working correctly. When the player has less than entity.health.max the scale is set to 0 instead of the calculated percent.

Code:

private void SetHealth(int amount)
{
  currentHealth = amount;
  float displayedHealth = currentHealth / entity.health.max;
  healthBar.transform.localScale = new Vector3(displayedHealth, 1, 1);
}