Hey! Im pretty new to Unity and currently making a 2D platformer game. I want a GUI image to appear when my character enters a trigger box, i have placed the image in the scene and hidden it and connected a trigger to it as it’s child. Then I made a script and placed it on the trigger, the script looks like this.
#pragma strict
private var textboxshow: boolean = false;
var textbox: UnityEngine.UI.Image;
function OnTriggerEnter2D(Col: Collider)
{
if(Col.tag == "Player")
{
textboxshow = true;
} else {
textboxshow = false;
}
}
function OnGUI()
{
if (textboxshow == true)
{
GetComponent.<Renderer>().enabled = true;
}
}
And when i enter the trigger volume the image does not appear, what have I done wrong? All help greatly appreciated!
(Edit: Fixed Collider to Collider2D, still does not work however)