Basically, you create a boolean variable AchievementVisible and this is what you toggle when the user actually click on the button, then you run a function that update both the text of the button and also show or hide the achievement gui. Notice that I store the button's label in a separate variable, my OnGUI function becomes clearer and not cluttered.
public var AchievementVisible:boolean = true;
public var HideText:String = "Hide Achievement List";
public var ShowText:String = "Show Achievement List";
private var currentText:String;
function Start(){
UpdateAchievementVisibility();
}
function UpdateAchievementVisibility(){
if (AchievementVisible){
currentText = HideText;
}else{
currentText = ShowText;
}
}
function OnGUI(){
if (GUILayout.Button(currentText)){
AchievementVisible = ! AchievementVisible;
UpdateAchievementVisibility();
}
if (AchievementVisible){
GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
GUI.Box (Rect (0,0,100,100), "Achievment");
GUI.EndGroup ();
}
}