simple collider stay

hello, im trying to make a simple UI text show up when i enter on a box colider
but its aways showing up, in the tutorial that watched this wanst happen
ehat i have done wrong on this?

public class npc1 : MonoBehaviour
{
    public GameObject Ttext;
    public GameObject dialogueobj;
    private bool coll;


  
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag ("NPC1"))
        {
            if (Input.GetKey(KeyCode.E))
            {
                dialogueobj.gameObject.SetActive(true);
            }


            Ttext.SetActive (true);
          
          
          
        }
    }

    private void OnTriggerExit(Collider other)
    {
        Ttext.SetActive(false);
        dialogueobj?.SetActive(false);
    }

}

in the video he doesnt used void update or start

Use Debug.Log to see what’s happening. Something like:

private void OnTriggerEnter(Collider other)
    {   Debug.Log(other.name+" has entered the trigger.");
        if (other.CompareTag ("NPC1"))
        {   Debug.Log(other.name+" has the right tag.");
            if (Input.GetKey(KeyCode.E))
            {
                Debug.Log("Player has pressed the key.");
                dialogueobj.gameObject.SetActive(true);
            }

Then you can look at your console output and see which parts of the code are executing.

1 Like

de debug work fine but the UI still active, until i get in the collider for the first then the code start working perfectly

problem solved, it was the UI the problem not the script, thx for your help