(Unity6)オブジェクトに耐久力をつける

(サンプルコード)

using UnityEngine;

public class DestroyObjest : MonoBehaviour
{
    public GameObject effectPrefab;
    public GameObject effectPrefab2;
    public AudioClip sound;
    // ★耐久力
    public int HP;
    
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Beam"))
        {
            // ★耐久力
            HP -= 1;

            GameObject effect = Instantiate(effectPrefab, other.transform.position, Quaternion.identity);
            Destroy(effect, 0.5f);

            // ★耐久力
            if (HP < 1)
            {
                // ★耐久力
                Destroy(gameObject);

                GameObject effect2 = Instantiate(effectPrefab2, transform.position, Quaternion.identity);
                Destroy(effect2, 1.0f);
                AudioSource.PlayClipAtPoint(sound, transform.position);
            }
        }
    }
}