102 lines
2.1 KiB
C#
102 lines
2.1 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class NoteController : MonoBehaviour
|
|
{
|
|
private float speed;
|
|
private bool isMoving = true;
|
|
private bool isInJudgeZone = false; // �������
|
|
|
|
private ParticleSystem hitEffect;
|
|
private Note linkedNote;
|
|
|
|
private void Awake()
|
|
{
|
|
|
|
hitEffect = GetComponentInChildren<ParticleSystem>();
|
|
linkedNote = GetComponent<Note>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isMoving)
|
|
{
|
|
transform.Translate(Vector3.down * speed * Time.deltaTime);
|
|
}
|
|
}
|
|
|
|
public void SetSpeed(float newSpeed)
|
|
{
|
|
speed = newSpeed;
|
|
}
|
|
|
|
public void StopMovement()
|
|
{
|
|
isMoving = false;
|
|
}
|
|
|
|
public void PlayHitEffect()
|
|
{
|
|
if (hitEffect != null)
|
|
{
|
|
hitEffect.Play();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetState()
|
|
{
|
|
speed = 0f;
|
|
isMoving = true;
|
|
isInJudgeZone = false;
|
|
|
|
if (hitEffect != null)
|
|
{
|
|
hitEffect.Stop();
|
|
hitEffect.Clear();
|
|
}
|
|
}
|
|
|
|
// �� OnTriggerEnter2D �� OnTriggerExit2D ������ Controller ��
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
if (collision.CompareTag("JudgmentLine"))
|
|
{
|
|
if (linkedNote != null)
|
|
{
|
|
isInJudgeZone = true;
|
|
TrackKeyManager.Instance.RegisterKey(linkedNote.GetTrackIndex(), linkedNote.GetKey());
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
{
|
|
if (collision.CompareTag("JudgmentLine"))
|
|
{
|
|
if (linkedNote != null)
|
|
{
|
|
isInJudgeZone = false;
|
|
TrackKeyManager.Instance.UnregisterKey(linkedNote.GetTrackIndex(), linkedNote.GetKey());
|
|
linkedNote.SetJudgeZone(isInJudgeZone);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// �� Note ��ѯ�Ƿ����ж�����
|
|
/// </summary>
|
|
public bool IsInJudgeZone()
|
|
{
|
|
return isInJudgeZone;
|
|
}
|
|
}
|