ui Text not responding to collider
Please help I've spent an entire day trying to figure this out and nothing seems to work. I am very new to Unity.
I would like for a text to pop up when I go over a certain area which is marked by a box collider on my terrain and then dissapear after 5 seconds. Everything seems to be working fine in the script as the text is not visible when I begin the game however it is never activated by the box collider. There are no error messages displayed either. I was following this tutorial: (https://www.youtube.com/watch?v=CNNeD9oT4DY)
Here is my script:
public GameObject uiObject;
void Start()
{
uiObject.SetActive(false);
}
//Update is called once per frame
void OnTriggerEnter(Collider player)
{
if (player.gameObject.tag == "Player")
{
uiObject.SetActive(true);
StartCoroutine("WaitForSec");
}
}
IEnumerator WaitForSec()
{
yield return new WaitForSeconds(5);
Destroy(uiObject);
Destroy(gameObject);
}
}
Have you tried to put a simple Debug.Log(player.gameObject.tag);
before the condition, inside the OnTriggerEnter
function? Are you sure all the conditions for collision detection are met? (Colliders, rigibodies, scripts, ...)
Answer by Nick15104 · Jun 16, 2018 at 05:36 AM
Use System.Collections; In order for Coroutines to work.