Fading In/Out Image Button and Starting New Scene Unity 3D Example

Here is a simple example of a button fading an image out and fading in a different image on a button in Unity 3d. I have also included how to go to a new scene/level using the button with either index of the scene or by title of the scene.

#pragma strict

var golfImage : Texture2D; // import your image 

function OnGUI () {

	// Fade an image out
	if(Time.time < 3){ // for the first 3 seconds
	    //Fade out
	    GUI.color.a = 1 - Time.time/3; 
		if (GUI.Button (Rect (Screen.width/2,Screen.height - 200 ,80,80), golfImage)) {
    	    Application.LoadLevel (1); // go to scene indexed at 1 if button is pressed

	//Fade in a button with text in
	    if(Time.time < 6){
	        //Fade in
		    GUI.color.a = (Time.time -3 )/3;
		    print("Time " + Time.time);
		    print((Time.time -3) /3);
	    if (GUI.Button (Rect (Screen.width/2,Screen.height - 200 ,80,80), "Start")) {
			Application.LoadLevel ("TEST"); // go to scene 'test' if pressed

    GUI.color.a = 1;	

	// Options
	if (GUI.Button (Rect (30, Screen.height -50,80,20), "Options")) {
		Application.LoadLevel ("Options");

    // Homepage
	if (GUI.Button (Rect (130, Screen.height -50,80,20), "Homepage")) {
		Application.LoadLevel (2);


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on
Fabulou wholesale Petr Mrazek jersey is back. Best choice to get the wholesale Petr Mrazek jersey is suitable for all style of people.