How to make reference to other from Collider inside Update?

I’m trying to do something that probably is simple: there is a NPC with a dialogue script. When player gets OnTriggerEnter with him, it triggers a dialogue function that is on the NPC.

The problem is: I want to use the Update function to check when the player press E (or other keys, later I see) to initiate the dialogue. But the dialogue is inside the OnTriggerEnter. I’ll show the code to be more clear.

void Update()
    {
        if (triggering)
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                calledDialogue = true;
            } 
        }
    }

Here I check if the player is triggering with the NPC, then checks if the player pressed E to set the var.

void OnTriggerEnter(Collider other)
    {
        if (other.tag == "NPC")
        {
            if (!triggering)
            {
                if(calledDialogue == true) other.GetComponent<DialogueTrigger>().TriggerDialogue();
            }

            triggering = true;
            triggeringNpc = other.gameObject;
        }
    }

Here, if not triggering, check if E was pressed to fire the function and run the dialogue.

But this way, the dialogue only opens when the player triggers and press E, then moves away and come back closer to the character (since the check in on OnTriggerEnter).

As newbie, I have no clue how can I use the other.GetComponent<DialogueTrigger>().TriggerDialogue(); inside the Update. Any light?

As usual, I found it like 5 minutes after posting it :smile:

Just set a private Collider otherNpc, then otherNpc = other; inside the OnTriggerEnter and finally:

otherNpc.GetComponent().TriggerDialogue();

…inside the Update.