Trigger Event on Text

I’m making a horror game and I want text to appear when you walk on an invisible cube.

Use a trigger BoxCollider and show the text in OnTriggerEnter

1 Like

I’m a bit confused I want TMP Text to show up here’s my script (remember Im not a pro on C# yet lol):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HuhScript : MonoBehaviour
{

// Start is called before the first frame update
void Start()
{

// Update is called once per frame
void Update()
{

}

void OnTriggerEnter(Collider other)
{
Debug.Log(other.name + " Has Entered!");
}

void OnTriggerExit(Collider other)
{
Debug.Log(other.name + " Has Exited!");
}

}
}

Script is from a tutorial that I followed along with

You put all of your other functions inside of the Start() function. You need to move them out of the Start function, or Unity will not call them. If you use standard code indentation you will notice a problem like this faster.

What do you mean? (Sorry I am a bit tired)

“{” marks the beginning of a function.

“}” marks the end of a function.

Your Start function starts here:

void Start()
{

Then it doesn’t end until nearly the end of the file. That means all of your other functions are inside of it. Take them out.

1 Like

I’m getting null reference errors now

Well now you’re making progress!