You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
859 B
C#

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<BallMotor>() == null || scoreCounter == null)
return;
collected = true;
GetComponent<Collider>().enabled = false;
scoreCounter.AddPoint();
gameObject.SetActive(false);
Destroy(gameObject);
}
}
}