using UnityEngine; public class RockHealth : MonoBehaviour { public int maxHp = 6; // หินทนกว่าต้นไม้ private int currentHp; public GameObject stoneDropPrefab; // ลาก 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 (stoneDropPrefab != null) { // เสกหินย่อยออกมาตรงตำแหน่งก้อนหิน Instantiate(stoneDropPrefab, transform.position + Vector3.up * 0.5f, Quaternion.identity); } } }