- Home /
Health Bar decreases in both directions
I have a health bar that is handled with a canvas that is applied to the first person camera within my multiplayer FPS game. When the player takes damage, the bar goes down in both directions, instead of going down like a normal health bar, and then meet when health is at 50%, and it then stops reading health and just looks as if it were 0% health.
TakeDamage function
public void TakeDamage(int amount)
{
if (!isServer)
{
return;
}
currentHealth -= amount;
if (currentHealth <= 0)
{
currentHealth = 0;
Debug.Log("Dead!");
}
}
Lower Healthbar Function
void OnChangeHealth(int currentHealth)
{
healthBar.sizeDelta = new Vector2(currentHealth, healthBar.sizeDelta.y);
}
The size of this RectTransform relative to the distances between the anchors. If the anchors are together, sizeDelta is the same as size. If the anchors are in each of the four corners of the parent, the sizeDelta is how much bigger or smaller the rectangle is compared to its parent.
I can guess your anchors are not set properly, There is a button that can set anchors on your left or right side of the game object.
Your answer
Follow this Question
Related Questions
Far Cry 3 Health Bar System 2 Answers
Trying to make a unique type of health 'bar' 1 Answer
Player health dropping far to fast 1 Answer