using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; public class HealthBarNumber2D : MonoBehaviour { public int life = 5; public TextMeshPro t; void Start() { t.text = "" + life; } void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { life--; t.text = "" + life; if (life <= 0) { Destroy(gameObject); } } } }