- Home /
 
fade in out multi images then go to next scene
Hello, Im just new in Unity 3D, I having a problem: I want to fade in fade out some logo (as a start game usual). I found out this script very useful: http://www.unifycommunity.com/wiki/index.php?title=FadeInOut When i try apply the 2nd image, it just appear at the same time with 1st image And after load logo, the scene doesnt go to scene 2 as i want. this is my code:
 // FadeInOut
 
               // //-------------------------------------------------------------------- // Public parameters //--------------------------------------------------------------------
public var fadeOutTexture : Texture2D;
public var fadeOutTexture2 : Texture2D;
public var fadeSpeed = 0.1;
var drawDepth = -1000;
var drawDepth1 = -1000;
//-------------------------------------------------------------------- // Private variables //--------------------------------------------------------------------
private var alpha = 1.0;
private var fadeDir = -1;
private var alpha1 = 1.0;
private var fadeDir1 = -1; //-------------------------------------------------------------------- // Runtime functions //--------------------------------------------------------------------
//--------------------------------------------------------------------
function OnGUI(){
 alpha += fadeDir * fadeSpeed * Time.deltaTime;  
 
 alpha = Mathf.Clamp01(alpha);   
 
 alpha1 += fadeDir1 * fadeSpeed * Time.deltaTime;  
 
 alpha1 = Mathf.Clamp01(alpha1);   
 
 GUI.color.a = alpha;
 
 GUI.depth = drawDepth;
 
 GUI.color.a = alpha1;
 
 GUI.depth = drawDepth1;
 
 GUI.DrawTexture(Rect(550, 250, 200, 83), fadeOutTexture);
 
 GUI.DrawTexture(Rect(550, 250, 200, 200), fadeOutTexture2);
 
 
               }
//--------------------------------------------------------------------
function fadeIn(){
 fadeDir = -1; 
 
 fadeDir1 = -2; 
 
 
               }
//--------------------------------------------------------------------
function fadeOut(){
 fadeDir = 1; 
 
 fadeDir1 = -2;     
 
               }
function Start(){
 alpha=1;
 
               fadeIn(); alpha1=2;
 fadeIn();
 
 Application.LoadLevel(2);
 
               }
Answer by SilverTabby · Jul 18, 2011 at 12:14 AM
Your problem is in the OnGUI() function
You're displaying BOTH textures EVERY time, no matter what. You are also doing the calculations for both.
You need to add some logic - a series of if-elses or a switch case block - so that you are ONLY fading in/out the texture that goes with the level.
I would:
-Add a public parameter that contains the number of the level you are going to. Update it every time you change levels BEFORE Application.LoadLevel()
-Remove fadeOutTexture & fadeOutTexture2 and replace them with a Texture Array ( Texture2D[] )
-Change the GUI function so that you are only doing the calculations for the fadeOutTextureArray[currentLevel]
Hope this helped
Your answer