Files
bansonic_beta_main/Assets/scripts/gamePlay_gameplay/NewBehaviourScript.cs
T

101 lines
2.3 KiB
C#

using UnityEngine;
public class Notes : MonoBehaviour
{
public int trackIndex; // Documentation text normalized.
public float hitTime; // Documentation text normalized.
private bool canBeJudged = false; // Documentation text normalized.
private bool isHit = false; // Documentation text normalized.
private void Update()
{
// Documentation text normalized.
if (canBeJudged && !isHit && Time.timeSinceLevelLoad > hitTime + 0.3f)
{
JudgeMiss();
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("JudgmentLine"))
{
canBeJudged = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("JudgmentLine"))
{
canBeJudged = false;
}
}
public void JudgeNote()
{
if (!canBeJudged || isHit) return; // Documentation text normalized.
float currentTime = Time.timeSinceLevelLoad;
float timeDifference = Mathf.Abs(currentTime - hitTime);
if (timeDifference <= 0.05f)
{
JudgePerfect();
}
else if (timeDifference <= 0.1f)
{
JudgeGreat();
}
else if (timeDifference <= 0.2f)
{
JudgeGood();
}
else if (timeDifference <= 0.3f)
{
JudgeMiss();
}
}
private void Recycle()
{
// Documentation text normalized.
if (NotePool.Instance != null)
{
NotePool.Instance.ReturnNote(gameObject, "red"); // Documentation text normalized.
}
else
{
Destroy(gameObject);
}
}
private void JudgePerfect()
{
Debug.Log($"Track {trackIndex}: Perfect!");
isHit = true;
Recycle();
}
private void JudgeGreat()
{
Debug.Log($"Track {trackIndex}: Great!");
isHit = true;
Recycle();
}
private void JudgeGood()
{
Debug.Log($"Track {trackIndex}: Good!");
isHit = true;
Recycle();
}
private void JudgeMiss()
{
Debug.Log($"Track {trackIndex}: Miss!");
isHit = true;
Recycle();
}
}