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);
}
}
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.