2026-06-12 노트생성

This commit is contained in:
2026-06-12 14:57:38 +09:00
parent d4a76a2a97
commit 1e0483f210
6 changed files with 93 additions and 15 deletions

View File

@@ -1,12 +1,47 @@
using System;
using UnityEngine;
public class RhythmNoteInstance : MonoBehaviour
{
public float HitTime; // 이 노트의 도달 시각
public float HitTime; // 이 노트의 도달 시각
[SerializeField] private float _missWindow = 0.15f; // 판정선을 이만큼 지나면 자동 Miss
private Vector3 _start; // 출발점
private Vector3 _target; // 목적지(판정선)
private float _spawnTime; // 생성된 시각 (= HitTime - leadTime)
private Func<float> _songTime; // 오디오 기준 현재 곡 시간 제공자
private Action<RhythmNoteInstance> _onMiss; // 지나쳐서 Miss 났을 때 통지
// 스폰 시 목적지·타이밍 주입 (B 방식)
public void Setup(Vector3 start, Vector3 target, float spawnTime, float hitTime,
Func<float> songTime, Action<RhythmNoteInstance> onMiss = null)
{
_start = start;
_target = target;
_spawnTime = spawnTime;
HitTime = hitTime;
_songTime = songTime;
_onMiss = onMiss;
transform.position = start;
}
private void Update()
{
// 판정선 향해 이동
// 너무 지나가면 Miss 처리 후 자기 파괴
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);
}
}
}