using UnityEngine; public class TreeHealth : MonoBehaviour { public int maxHp = 5; private int currentHp; public GameObject woodDropPrefab; // ลาก Prefab ขอนไม้มาใส่ใน Inspector void Start() { currentHp = maxHp; } public void TakeDamage(int damage) { currentHp -= damage; // [เพิ่มบรรทัดนี้] เพื่อเช็คใน Console ว่าเลือดลดจริงไหมเวลากดฟัน Debug.Log(gameObject.name + " โดนฟัน! เลือดเหลือ: " + currentHp); if (currentHp <= 0) { DropItem(); Destroy(gameObject); // ลบต้นไม้ทิ้ง } } void DropItem() { if (woodDropPrefab != null) { // เสกขอนไม้ออกมาตรงตำแหน่งต้นไม้ Instantiate(woodDropPrefab, transform.position + Vector3.up * 0.5f, Quaternion.identity); } } }