system
1
Hi, I have written this code which displays a GUI image when the player enters a box collider. However, I want the image to disappear once they have left the box collider. I thought that I was doing this with the else statement, as I have created a blank image called "clear". (However if you know of a way of doing this without using an image that would be good)
var Blank : Texture2D;
var Crouch : Texture2D;
function OnTriggerEnter(otherCollider : Collider) {
var g_infotext = gameObject.Find("g_infotext");
if (otherCollider.tag == "ColliderCrouch") {
g_infotext.guiTexture.texture = Crouch;
}
else {
g_infotext.guiTexture.texture = Blank;
}
}
Thanks
It's quite simply, really, as all you have to do is use a `boolean` variable and an `OnTriggerExit` function as well as an `OnTriggerEnter` function. The following code should do the trick:
var Crouch : Texture2D;
var canShow = false;
function OnTriggerEnter(other : Collider) {
var g_infotext = gameObject.Find("g_infotext");
canShow = true;
if (other.gameObject.CompareTag ("ColliderCrouch") && canShow) {
g_infotext.guiTexture.texture = Crouch;
}
}
function OnTriggerExit (otherCollider : Collider) {
canShow = false;
}