26 lines
691 B
C#
26 lines
691 B
C#
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;
|
|
|
|
// Debug.Log($"Setting health {amount} / {maxHealth}");
|
|
|
|
healthBarFill.localScale = new Vector3(startScale.x * amountMult, startScale.y,startScale.z );
|
|
}
|
|
} |