I have this code to detect if the player is in or out of a trigger when I click a button. BUT how can I do to appears a message in the canvas with "Map on"/"Map off" if the player is in/out the trigger? And How can I do it to add a UI button in the canvas instead of the key space?
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 UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class DetectarMapa_BT : MonoBehaviour {
public Button b1;
private bool isTriggerred;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Player"))
isTriggerred = true;
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("Player"))
isTriggerred = false;
}
void OnEnable()
{
b1.onClick.AddListener (() => buttonCallBack (b1));
}
private void buttonCallBack(Button buttonPressed)
{
if (buttonPressed == b1) {
isTriggerred = true;
}
}
void OnDisable()
{
b1.onClick.RemoveAllListeners();
}
}