using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpriteHealthBar : MonoBehaviour { private Vector3 startScale; public Transform healthBarFill; public float health; void Awake() { startScale = healthBarFill.localScale; } public void SetHealth(float amount, float maxHealth = 100f){ if(maxHealth == 0 ){Debug.Log("max health is 0"); return;} health = amount; float amountMult = amount / maxHealth; if(amountMult<0){amountMult=0;} //Debug.Log($"Setting health on {transform.name}: {amount} / {maxHealth}"); healthBarFill.localScale = new Vector3(startScale.x * amountMult, startScale.y,startScale.z ); } }