using System; using UnityEngine; public class RhythmNoteInstance : MonoBehaviour { [HideInInspector] public float HitTime; // 이 노트의 도달 시각 [SerializeField] private float _missWindow = 0.15f; // 판정선을 이만큼 지나면 자동 Miss private Vector3 _start; // 출발점 private Vector3 _target; // 목적지(판정선) private float _spawnTime; // 생성된 시각 (= HitTime - leadTime) private Func _songTime; // 오디오 기준 현재 곡 시간 제공자 private Action _onMiss; // 지나쳐서 Miss 났을 때 통지 // 스폰 시 목적지·타이밍 주입 (B 방식) public void Setup(Vector3 start, Vector3 target, float spawnTime, float hitTime, Func songTime, Action onMiss = null) { _start = start; _target = target; _spawnTime = spawnTime; HitTime = hitTime; _songTime = songTime; _onMiss = onMiss; transform.position = start; } private void Update() { if (_songTime == null) return; float now = _songTime(); // SongTime 기반 보간: spawnTime → HitTime 구간을 0→1로 float t = Mathf.InverseLerp(_spawnTime, HitTime, now); transform.position = Vector3.LerpUnclamped(_start, _target, t); // 판정선을 missWindow 이상 지나치면 Miss 처리 후 자기 파괴 if (now > HitTime + _missWindow) { _onMiss?.Invoke(this); Destroy(gameObject); } } }