- Home /
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?
If anyone has any idea on what I need to do, I would be eternally grateful.
I can show you the script I found on youtube for changing 3d text but I am not certain it will help you using c# using UnityEngine; using System.Collections; public class StartGameScript : $$anonymous$$onoBehaviour { void On$$anonymous$$ouseEnter() { gameObject.renderer.material.color = Color.blue; } void On$$anonymous$$ouseExit() { gameObject.renderer.material.color = Color.white; } void On$$anonymous$$ouseDown() { Application.Quit(); } }
what the script dose is change 3d text mesh color and quit.
Answer by Jamora · Jul 11, 2013 at 12:08 AM
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;
}
Adding in that extra LoadLinePressed worked perfectly! Thank you very much.
Answer by Yokimato · Jul 11, 2013 at 12:00 AM
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;
}
Unfortunately, that didn't do what I wanted it to. I want it to change the font color of --ONLY-- the button that is clicked, not all of them.
Your answer
Follow this Question
Related Questions
UI Button color 1 Answer
Blend into next color instead of jumping to next color 1 Answer
Trying to change the color of a game object. 1 Answer
Distribute terrain in zones 3 Answers
Referencing color change when object is 'deselected' 2 Answers