Hello, I have a problem with disabling a GUIText, in the scene “OnTriggerExit”. The code at the very bottom doesn’t throw and error until I have exited the collider and shows “Not set to an instance of an object”. I’m not really sure how to disable this GUIText.
using UnityEngine;
using System.Collections;
public class MyController : MonoBehaviour
{
public GameObject Door;
bool Mission01 = false;
public GUIText XPtext;
void OnTriggerEnter (Collider Collided)
{
if (Collided.gameObject.tag == "MerchantCollider")
{
XPtext.text = "Go collect item";
//GetComponent.<XPtext>().enabled = true;
}
else if (Collided.gameObject.tag == "Door")
{
//Debug.Log ("Door");
if (Mission01)
Door.gameObject.animation.Play ("Open");
}
else if (Collided.gameObject.tag == "Cube")
{
Mission01 = true;
Destroy (Collided.gameObject);
}
}
void OnTriggerExit (Collider Collided)
{
if (Collided.gameObject.tag == "MerchantCollider")
{
var guiComponent = GetComponent("XPtext").guiText;
guiComponent.enabled = false;
}
}
}
Thanks!