トリガーが検出されたときにUIテキストを追加するにはどうすればよいですか? プレイヤーがトリガーに入っているかどうかを検出するためにこのコードを持っていますが、プレイヤーがトリガーに出入りすると「地図上」/「地図オフ」のキャンバスにメッセージが表示されます。ありがとう!トリガーが検出されたときのUIテキストの追加
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);
}
}
あなたも試していませんでした。クリックボタン[パート](http://stackoverflow.com/q/42632196/3785314)を実装できませんでしたか?尋ねると答えが得られるだけでなく、何か試したことを示すことは良いことです。それ以外の場合は、人々が最初から最後まであなたのゲームスクリプトを書くことを望んでいる。 – Programmer
申し訳ありません今、私はクリックボタンの部分を実装する時間がありません。試してみると、ここに書きます。 – Angelsm