Multiple Button Modifications

Hey guys, so I’m working with a load screen, where someone can select one of 30 save games.

foreach(var i in text)
{
	if(GUI.Button(new Rect(0, y, 376, 20), i, "LoadLine"))
	{
		LoadSkin.button.font.material.color = Color.yellow;
		if(loadGame == i.ToString()){
			//Load Game
		}else{
			loadGame = i.ToString();
			Debug.Log("Trying to load: " + i.ToString());
		}
		Debug.Log(loadGame);
	}
	y = y + 20;
}

How am I able to change the font color of the button they click?

LoadSkin.button.font.material.color = Color.yellow;

throws a null pointer exception. Any ideas? Should I be using something other than a button?

You need to change the “Active” setting in your GUISkin’s custom style to whatever color you want when the user clicks on the button. Apparently the background texture can not be “None”, or it won’t work.

If you want to permanently change the text color of the button the user has clicked on, store the buttons that have been pressed, then create a different style for pressed buttons, which is chosen if the button has been pressed.

foreach (string i in text) {
			if(nextButtonAlreadyPressed){
				if(GUI.Button(new Rect(0, y, 376, 20), i, "LoadLinePressed")){
					ButtonFunction();}
			}else if(GUI.Button(new Rect(0, y, 376, 20), i, "LoadLine")){
					ButtonFunction();
			} 
			y = y + 20;
		}

foreach(var i in text)
{
GUI.color = your_color_here; //<— SET COLOR BEFORE DRAW
if(GUI.Button(new Rect(0, y, 376, 20), i, “LoadLine”))
{
LoadSkin.button.font.material.color = Color.yellow;
if(loadGame == i.ToString()){
//Load Game
}else{
loadGame = i.ToString();
Debug.Log("Trying to load: " + i.ToString());
}
Debug.Log(loadGame);
}
GUI.color = default_color_here; //<-- Don’t forget to revert it afterwards
y = y + 20;
}