70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using UnityEngine;
|
|
using System;
|
|
|
|
public class HoldNoteController : MonoBehaviour
|
|
{
|
|
private bool isInsideJudgeZone = false;
|
|
public event Action<bool> OnJudgeZoneChanged;
|
|
private bool isMoving = false;
|
|
private float speed = 0f; // 音符下落速度
|
|
private float activationTime; // 用于延迟启用下落
|
|
|
|
private void Update()
|
|
{
|
|
// **控制音符下落**
|
|
if (!isMoving && Time.time >= activationTime)
|
|
{
|
|
isMoving = true;
|
|
}
|
|
|
|
if (isMoving)
|
|
{
|
|
transform.Translate(Vector3.down * speed * Time.deltaTime);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置音符延迟下落的时间
|
|
/// </summary>
|
|
public void SetSegmentDelay(float segmentDelay)
|
|
{
|
|
activationTime = Time.time + segmentDelay;
|
|
isMoving = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置音符的下落速度
|
|
/// </summary>
|
|
public void SetSpeed(float newSpeed)
|
|
{
|
|
speed = newSpeed;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停止音符下落(当音符被击中或Miss时)
|
|
/// </summary>
|
|
public void StopMovement()
|
|
{
|
|
isMoving = false;
|
|
}
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
if (!collision.CompareTag("JudgmentLine")) return;
|
|
|
|
isInsideJudgeZone = true;
|
|
OnJudgeZoneChanged?.Invoke(true);
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
{
|
|
if (!collision.CompareTag("JudgmentLine")) return;
|
|
|
|
isInsideJudgeZone = false;
|
|
OnJudgeZoneChanged?.Invoke(false);
|
|
}
|
|
|
|
public bool IsInsideJudgArea()
|
|
{
|
|
return isInsideJudgeZone;
|
|
}
|
|
}
|