Hello. I'm developing a vertical scrolling rhythm game(like step mania, friday night funkin) and I ran into the problem that I can't figure out how to make a long note, a note that you need to hold for a certain amount of time. I've been following some tutorials but none of them shows how to do it properly.
Here's my current code for the tap notes(you need to hit the key only once):
void Update()
{
if (Input.GetKeyDown(keyToPress))
{
if (canBePressed)
{
gameObject.SetActive(false);
Debug.Log("Hit");
}
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Activator")
{
canBePressed = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Activator")
{
canBePressed = false;
Destroy(gameObject, 0.25f);
}
}
}
I thought maybe I should create a variable TimeToBeHeld, that can be obtained by multiplying the length of the note sprite collider by the tempo of the song and create a conditional loop to check if I held enough time. But I don't know how to make note being held visually without destroying it when it just got into the collider of the button(like on the screenshot below). I'm a beginner at both programming and unity so I don't know much. Does anyone know how to do it right?
Any help will be appreciated.
(sorry if there will be any grammar mistakes, I hope it's understandable what I've written)