using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PlayerHealth : MonoBehaviour{ public Image health; public float hp, maxHp = 12f; // Start is called before the first frame update void Start(){ hp = maxHp; } // Update is called once per frame void Update(){ } public void TakeDamage(float amount){ hp = Mathf.Clamp(hp - amount, 0f, maxHp); health.transform.localScale = new Vector2(hp / maxHp / 100, 0.00927f); } public void AddHealth(float amount){ hp = Mathf.Clamp(hp + amount, 0f, maxHp); health.transform.localScale = new Vector2(hp / maxHp / 100, 0.00927f); } }