I am trying to make it so when the button is pressed it changes its own text. Heres what Ive been trying with no success.
var achButton = GUILayout.Button("Show Achievement List");
achButton.text = "Hide Achievement List";
help is appreciated.
This is one way to do it:
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;
currentText = HideText;
currentText = ShowText;
AchievementVisible = ! AchievementVisible;
GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
GUI.Box (Rect (0,0,100,100), "Achievment");
Hopefully the rest is all self explanatory.
Create a string and store what you want displayed in that, then update the contents of the string and the buttons text will update along with it.
Heres some psudeo code
var buttonText : String = "Show Trophies";
var buttonPressed : Boolean = false;
buttonText = "Hide Trophies"
buttonText = "Show Trophies"
buttonPressed = True;
Hope that helps! :)