fork download
  1. using UnityEngine;
  2.  
  3. public class Enemy : MonoBehaviour
  4. {
  5. public float health = 100f;
  6.  
  7. public void TakeDamage(float amount)
  8. {
  9. health -= amount;
  10. if (health <= 0f)
  11. {
  12. Die();
  13. }
  14. }
  15.  
  16. void Die()
  17. {
  18. // เอฟเฟกต์ตอนตาย (เช่น ระเบิด, เสียง, อนิเมชัน)
  19. Destroy(gameObject); // ลบศัตรูออกจากเกม
  20. }
  21. }
Success #stdin #stdout 0.04s 25876KB
stdin
Standard input is empty
stdout
using UnityEngine;

public class Enemy : MonoBehaviour
{
    public float health = 100f;

    public void TakeDamage(float amount)
    {
        health -= amount;
        if (health <= 0f)
        {
            Die();
        }
    }

    void Die()
    {
        // เอฟเฟกต์ตอนตาย (เช่น ระเบิด, เสียง, อนิเมชัน)
        Destroy(gameObject); // ลบศัตรูออกจากเกม
    }
}