using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerHealth : MonoBehaviour{ public int maxHp; [HideInInspector] public float hp; public GameObject healthBar; // Start is called before the first frame update void Start(){ hp = maxHp; } public void TakeDamage(float damage){ hp -= damage; if (hp > 0 && hp > damage){ healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y); }else if (hp < damage){ healthBar.transform.localScale = new Vector2(0, healthBar.transform.localScale.y); } } }