- Home /
How do I trigger GUI elements
I want an image to fly in from the left screen when I run over a trigger object in my scene, then animate back out to the left when I exit the trigger collider.
Nothing I'm trying is working. The latest thing I've tried is, I have an object with the following script attached.
var showSlideOne : boolean; var showSlideSeven : boolean;
var slide01 : Texture2D; var slide07 : Texture2D;
var position01 : Rect; var position07 : Rect;
function Start () { var CurrentX_01 = 0.0; var CurrentX_07 = 0.0;
position01 = Rect(CurrentX_01,0,1024,768);
position07 = Rect(CurrentX_07,0,1024,768);
}
function OnGUI () {
if (showSlideOne) {
GUI.DrawTexture( position01, slide01 );
}
if (showSlideSeven) {
GUI.DrawTexture( position07, slide07 );
}
}
Then I have the following script attached to the collider object.
function OnTriggerEnter (col : Collider) { print("On Ducts");
showSlideSeven = true;
} function OnTriggerExit (col : Collider) { print("Off Ducts");
showSlideSeven = false;
}
The trigger doesn't show or hide the images, but the print commands work. Can anyone tell me why, and how to fix the images triggering?
Answer by Alec-Slayden · Mar 01, 2011 at 09:25 PM
Your showSlideSeven and showSlideOne variables are local to the first script. That means in order to change them in a different script, you'll need to access the other object and then access the script on that object.
By defining the variables as you have it in the second script, They are created on the fly local to those functions, so they're separate and completely unused variables.
If you refer to these variables often throughout all your scripts, you may want to define them as "static var" instead of "var"
Then, if we say the script is called "scriptname", all you have to do is:
scriptname.showSlideOne = true;