Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using TMPro;
- using UnityEngine;
- public class HealthManager : MonoBehaviour
- {
- public int maxHealth = 100;
- private int currentHealth;
- public TextMeshProUGUI healthText;
- void Start()
- {
- currentHealth = maxHealth;
- UpdateHealthText();
- }
- void UpdateHealthText()
- {
- healthText.text = "HP: " + currentHealth.ToString();
- }
- public void TakeDamage(int damage)
- {
- currentHealth -= damage;
- UpdateHealthText();
- if (currentHealth <= 0)
- {
- Die();
- }
- }
- void Die()
- {
- // Die logic
- }
- public void DecreaseHP(int amount)
- {
- currentHealth -= amount;
- UpdateHealthText();
- }
- private void OnTriggerEnter2D(Collider2D collision)
- {
- if (collision.gameObject.tag == "Enemy")
- {
- TakeDamage(1); // Предполагается, что урон от врага составляет 1
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement