using UnityEngine; namespace Class03 { // 공과의 접촉을 처리하고 한 번만 점수를 지급합니다. [RequireComponent(typeof(SphereCollider))] public sealed class StarPickup : MonoBehaviour { [SerializeField] private ScoreCounter scoreCounter; private bool collected; public void Initialize(ScoreCounter counter) => scoreCounter = counter; private void OnTriggerEnter(Collider other) { if (collected || other.attachedRigidbody == null || other.attachedRigidbody.GetComponent() == null || scoreCounter == null) return; collected = true; GetComponent().enabled = false; scoreCounter.AddPoint(); gameObject.SetActive(false); Destroy(gameObject); } } }