How can I add a UI Text when the trigger is detected? I have this code to detect if the player is in or out of a trigger BUT I want to appears a message in the canvas with "Map on"/"Map off" if the player is in/out the trigger. Thanks!
public class MapDetect : MonoBehaviour {
private bool isTriggered;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
isTriggered = true;
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("Player"))
isTriggered = false;
}
void Update(){
if(Input.GetKey(KeyCode.Space)){
Debug.Log(isTriggered);
}
}
}
UPDATE CODE:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DetectarMapa : MonoBehaviour {
public GameObject T1;
public GameObject T2;
public float time = 3;
void Start ()
{
T1.SetActive (true);
StartCoroutine(Message1());
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
T2.SetActive (true);
StartCoroutine(Message2());
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("Player"))
T1.SetActive (true);
StartCoroutine(Message1());
}
IEnumerator Message1 ()
{
yield return new WaitForSeconds(time);
T1.SetActive (false);
}
IEnumerator Message2 ()
{
yield return new WaitForSeconds(time);
T2.SetActive (false);
}
}