I'm making a simple health bar in Unity 3D. Health bar UI is made from images. I'm having a problem with setting bar's position based on health percentage. Here's a script part:
percentHealth = (currentHealth / maxHealth) * 100; //get's health percentage.
HealthBarHealth.transform.localPosition = new Vector3(healthBarCurrentX, 0); //moves health bar
I want healthBarCurrentX to be calculated from these values:
percentHealth - percentage calculated from max health and current. healthBarMaxX = 0f - health bar's position at 100% health. healthBarMinX = -273.5f - bar's position at 0% health.
So when health is 50%, currentX is at -136.65, etc.