Hello, I am currently learning Unity by following a very basic guide, and I noticed an issue with my game so far, and I was hoping to get some advice possibly? I hope this is in the right section of the forums, sorry if it’s not.
On certain objects and obviously for character dialogue later, I have a box collider that is a trigger for dialogue, using OnTriggerStay2D. When the player presses the Z key the dialogue box appears, but it usually takes 2 or 3 presses of Z for it to appear, intermittently (sometimes Z works immediately, sometimes it doesn’t), is my first problem.
My other problem is that this only works about six times before I have to move away and back into the collider in order to trigger the dialogue again. Is there a finite time with OnTriggerStay2D? Or is there something I’m missing?
A point in the right direction would be greatly appreciated. I’m not looking for people to write my code for me, only advice as I am still learning.
Thank you.
void OnTriggerStay2D(Collider2D other)
{
// If the player is colliding with the object
if (other.tag == "Player")
{
// Check if the player presses the key Z
if (Input.GetKeyUp(KeyCode.Z))
{
//Check to make sure the dialogue box isn't already running
if (!dMan.dialogueActive)
{
thePlayer.allowedToMove = false;
dMan.dialogueLines = dialogueLines;
dMan.currentLine = 0;
dMan.ShowDialogue();
} // END CHECK ACTIVE
} // END CHECK PRESS Z
} // END CHECK PLAYER
} // END ONTRIGGERSTAY2D