If I press a key where the decision line overlaps two notes, both notes disappear at once. I’ve been thinking about it for hours, but it didn’t work, so I’m asking a question…
When creating each note, a noteID was assigned and the numbers increased sequentially starting from 1.
I created a note number to react to next in the game manager, and if the two are the same, I made that note disappear. As the notePassCount value in the game manager rises, all overlapping notes disappear.
public void NoteHit() //GameManager.cs
{
Debug.Log("Hit!");
notePassCount++;
}
public void NoteMissed()
{
Debug.Log("Missed!");
notePassCount++;
}
void Update() //NoteScript.cs
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
if (canBePressed == true && noteNumbering.noteID == GameManager.instance.notePassCount)
{
ParentObject.SetActive(false);
GameManager.instance.NoteHit();
}
}
}
public void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "SecondNeedle")
{
canBePressed = true;
}
}
public void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "SecondNeedle" && ParentObject.activeSelf)
{
canBePressed = false;
GameManager.instance.NoteMissed();
ParentObject.SetActive(false);
}
}
public class NoteNumbering : MonoBehaviour
{
public int noteID;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void SetNoteID(int id)
{
noteID = id;
}
}
Every Note has notescript.cs and noteNumbering.cs
user24880186 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.