1
0
Fork 0
boss-room/Assets/Scripts/Healthbar.cs
2021-07-11 14:58:03 -05:00

37 lines
836 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Healthbar : MonoBehaviour
{
public GameObject healthBar;
private float health;
private float full = 1.0f;
private float empty = 0.0f;
public float damage(float amount)
{
Debug.Log("Damage");
Debug.Log(amount);
if (health - amount < empty) health = empty;
else health -= amount;
return health;
}
void Start()
{
Vector2 originalScale = new Vector2(full, healthBar.transform.localScale.y);
healthBar.transform.localScale = originalScale;
health = full;
}
void Update()
{
if (health <= empty) Debug.Log("DEAD :(");
if (health >= empty) {
Vector2 newScale = new Vector2(health, healthBar.transform.localScale.y);
healthBar.transform.localScale = newScale;
}
}
}