Hi guys,
struggling with what should be basic, we’re switching a GUI text on with the following script when u walk into an object with the FPS controller, that has a tag called “head1” -
function OnControllerColliderHit (hit : ControllerColliderHit){
if (hit.collider.gameObject.tag == "head1") {
switcher.switcher();
}
}
This references a static function called “switcher” in a script also called “switcher”, below -
//function to switch GUI Texture on / off
static function EnableTaggedGUIText(tag : String, enable : boolean) {
//check for an object with a certain tag
var go = GameObject.FindWithTag(tag);
if(go) {
// if found, address its GUITexture component
var gt = go.GetComponent(GUIText);
if(gt) {
//..and enable it
gt.enabled=enable;
}
// if not found state that there is no GUITexture on the gameObject
else {
Debug.Log("Error: The GameObject does not have a GUIText component to enable", go);
}
}
//if no tagged game object matching found, return following statement
else {
Debug.Log("Error: Could not find a GameObject tagged "+tag);
}
}
function Start(){
EnableTaggedGUIText("head", false);
}
static function switcher(){
EnableTaggedGUIText("head", true);
}
static function off(){
EnableTaggedGUIText("head", false);
}
This script ^^ is attached to the GUItext itself.
That all works fine, but as you can see in the switcher script, we also have a function called “off” to switch off our GUIText, and we need to trigger this when we walked away from the object that has the “head1” tag.
Surely this is a straightforward thing to do? Cant seem to use CollisionExit because it doesnt work with character collider. Can anyone suggest a straightforward way of doing this? Tearing my hair out on this one…
Thanks
Will[/code]