Fade GUI in and another out

Hi all,

Im trying to get a a GUI button when pressed to fade out and fade another GUI button in.

I have been able to get the first button to fade out but I am unsure how to fade the second one in, here is my code so far,

var showGUI:boolean = true; 
var alpha:float;
 
 
 var glasswater: Texture2D;
 
function Update(){
   if(showGUI){
      FadeIn();
   } else {
      FadeOut();
   }
};

function FadeOut(){
   alpha = Mathf.Lerp(alpha,0,Time.deltaTime*5);
};
 
 
function FadeIn(){
   alpha = Mathf.Lerp(alpha,1,Time.deltaTime*5);
};
 
function OnGUI(){
GUI.color.a = alpha;

if(GUI.Button(Rect(Screen.width/2 - 77.625, Screen.height/2- 146.125, 155.25, 372.25), glasswater)){

	showGUI=false;

	};

};

Thanks
D

I could recomend you my asset - Screen Fader - Unity Asset Store - The Best Assets for Game Making

With it your code could looks like this:

OnGUI()
{
...
	if(GUI.Button(Rect(Screen.width/2 - 77.625, Screen.height/2- 146.125, 155.25, 372.25), glasswater)){
		ScreenFader.Instance.FadeIn().StartCoroutine(SwitchButtonsMethod()).FadeOut();
	};
...
}

IEnumerator SwitchButtonsMethod()
{
	button1visible = !button1visible;
	button2visible = !button2visible;
	yield break;
}