- Home /
Fade GUITexture in when previous GUITexture fade out
Hi. I have 3 GUITextures. Well, i want to let them fade in and out.
So
GUITexture 1 fade in -- 3 seconds --> Texture 1 fade out --> wait 1 second -->
GUITexture 2 fade in -- 3 seconds --> Texture 2 fade out --> wait 1 second -->
GUITexture 3 fade in -- 3 seconds --> Texture 3 fade out --> wait 1 second --> Go to other scene.
I tried a lot of examples like Unifycommunity and others.
But i still don't know how to make this like i want to make it. Someone can help me please?
Thanks in advance
**EDIT*
Please someone help me. And i'm looking for JS. Please help
Answer by Berenger · Jan 27, 2012 at 05:27 PM
Check out coroutines. Something like :
Ienumerator NextScene()
{
StartCoroutine( FadeIn( tex1 ) );
yield return new WaitForSeconds( wait1 );
StartCoroutine( FadeOut( tex1 ) );
yield return new WaitForSeconds( wait2 );
StartCoroutine( FadeIn( tex2 ) );
yield return new WaitForSeconds( wait1 );
StartCoroutine( FadeOut( tex2 ) );
yield return new WaitForSeconds( wait2 );
StartCoroutine( FadeIn( tex3 ) );
yield return new WaitForSeconds( wait1 );
StartCoroutine( FadeOut( tex3 ) );
yield return new WaitForSeconds( wait2 );
}
I would like it in JavaScript because all my scripts are in JS. Thanks for your help :D
But i'm looking for JS.
Help please
Easy enough. Delete all the "return new", replace StartCoroutine ( function()) by function(), and IEnumerator by function, and here you go :)
So the JS should be like this?
public var guitext1 = GUITexture;
public var guitext2 = GUITexture;
public var guitext3 = GUITexture;
function NextScene()
{
function ()
yield WaitForSeconds (5);
StartCoroutine( FadeOut( guitex1 ) );
yield WaitForSeconds (5);
function ()
yield WaitForSeconds (5);
StartCoroutine( FadeOut( guitex2 ) );
yield WaitForSeconds (5);
function ()
yield WaitForSeconds (5);
StartCoroutine( FadeOut( guitex3 ) );
yield WaitForSeconds (5);
}
If yes? it gives me an error with: unexpected yield :S
Answer by Berenger · Jan 29, 2012 at 01:37 AM
var fadeIn: float;
var fadeOut: float;
function Start()
{
NextScene();
}
function NextScene()
{
FadeIn();
yield WaitForSeconds( fadeIn);
FadeOut();
yield WaitForSeconds( fadeOut);
FadeIn();
yield WaitForSeconds( fadeIn);
FadeOut();
yield WaitForSeconds( fadeOut);
FadeIn();
yield WaitForSeconds( fadeIn);
FadeOut();
yield WaitForSeconds( fadeOut);
}
function FadeIn(){
var counter : float = 0f;
while( counter < fadeIn){
print ( "FadeIn alpha : " + Mathf.Lerp( 0, 1, counter / wait1 ) );
counter += Time.deltaTime;
yield WaitForEndOfFrame();
}
}
function FadeOut() {
var counter : float = 0f;
while( counter < fadeOut)
{
print ( "FadeOut alpha : " + Mathf.Lerp( 1, 0, counter / wait1 ) );
counter += Time.deltaTime;
yield WaitForEndOfFrame();
}
}
Really, thank you.
But i have only one question. Were should I assign the GUITextures?
Your answer
Follow this Question
Related Questions
Fade multiple GuiTextures in ONE Javascript 1 Answer
How to fade between 3 GUI textures? 1 Answer
How to fade a scene in/out 1 Answer
Circular in/out effect for scene 1 Answer