Here’s the code I have on the doors in my level with each door containing a collision trigger:
function Update () {
if(Input.GetButtonDown("Fire1"))
doorButtonPressed=true;
else
doorButtonPressed=false;
}
function OnTriggerEnter (collisionInfo: Collider)
{
if (collisionInfo.tag == "Player")
{
doorPromptRef.renderer.enabled = true;
doorPromptText.text = "[X] ENTER";
}
}
function OnTriggerStay (collisionInfo: Collider)
{
if (collisionInfo.tag == "Player")
{
if(doorButtonPressed)
{
GoToRoom();
}
}
}
This works 90% of the time, but occasionally it will miss a button press (I test by rapidly going back and fourth between two doors).
I suspect this is occurring because Unity Script reference states “OnTriggerStay is called almost all the frames for every Collider other that is touching the trigger.” But I don’t know of a more proper way to go about handling this and don’t want to make a hacky workaround yet.
I humored changing GetButtonDown to just GetButton, but if the player holds down the button they will warp back and fourth between doors too rapidly.
On a random side note that may or may not be relevant: I’m using ex2D.