Basicially, when a collision occurs I wish for my UI text to be displayed. Here is the method I am using to accomplish this, the script is attached to my UI Text GameObject:
Within Void Start I can successfully enable and disable the UI Text, however within the OnCollisionEnter2D, the GetComponent<Text>().enabled = true; just doesn't get recognised when a collision is made and so the text doesn't become true (doesn't show). I can confirm that a collision is detected, so that's not the problem.. I suspect it's something to do with the .enabled method? Could somebody help me with this.
Code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class text : MonoBehaviour {
// Use this for initialization
void Start () {
GetComponent<Text>().enabled = false;
}
void OnCollisionEnter2D(Collision2D Man)
{
if (Man.gameObject.tag == "house")
GetComponent<Text>().enabled = true;
}
}
Within Void Start I can successfully enable and disable the UI Text, however within the OnCollisionEnter2D, the GetComponent<Text>().enabled = true; just doesn't get recognised when a collision is made and so the text doesn't become true (doesn't show). I can confirm that a collision is detected, so that's not the problem.. I suspect it's something to do with the .enabled method? Could somebody help me with this.