- Home /
How to fade between 3 GUI textures?
I've looked at many GUI texture fading scripts, but I can't seem to alter them to work how I want them to. I have 3 GUI textures, and a variable I need them to work with.
As soon as the game starts, the first GUI texture is displayed, and stays on screen.
When the "anxiety" variable is above 10, the first texture fades out, as the second one fades in.
When the anxiety variable reaches above 20, the second texture fades out, as the third one fades in.
This seems so simple, but I can't get it to work! Can someone please give me a hand here? I'm using Java.
Answer by aldonaletto · Jul 15, 2012 at 01:20 AM
If you're using GUITextures, you must have 3 of them (one for each texture) and control the individual guiTexture.color.a values - 0 is invisible, 1 is fully visible. You could define limits where the crossfade occurs, and create AnimationCurves to control each texture - like this:
var anxiety: float = 10; // your anxiety variable var gTex1: GUITexture; // drag the first texture here var gTex2: GUITexture; // drag the 2nd here var gTex3: GUITexture; // drag the 3rd here var lim12: float = 10; // 1st to 2nd limit var lim23: float = 20; // 2nd to 3rd limit var crossRange: float = 5; // crossfade range
public var alpha1: AnimationCurve; public var alpha2: AnimationCurve; public var alpha3: AnimationCurve;
function Start(){ var margin = crossRange/2; // find the necessary curve points: var v1 = lim12-margin; var v2 = lim12+margin; var v3 = lim23-margin; var v4 = lim23+margin; // create curves for each texture: alpha1 = AnimationCurve(Keyframe(0,1), Keyframe(v1,1), Keyframe(v2,0)); alpha2 = AnimationCurve(Keyframe(v1,0), Keyframe(v2,1), Keyframe(v3,1), Keyframe(v4,0)); alpha3 = AnimationCurve(Keyframe(0,0), Keyframe(v3,0), Keyframe(v4,1)); }
function Update(){ gTex1.color.a = alpha1.Evaluate(anxiety); gTex2.color.a = alpha2.Evaluate(anxiety); gTex3.color.a = alpha3.Evaluate(anxiety); }
Thank you, that worked beautifully! I really appreciate it!