Simple question, is there a way to set the default Unity GUI style to a GUIStyle object.
This below:
public Texture2D background;
GUIStyle style = new GUIStyle();
void Start(){
if(background != null){
style.normal.background = background;
}
}
void OnGUI(){
if(background != null){
if(GUI.Button (new Rect(200,200,100,100),"Button",style)){}
}
else if (background == null){
if(GUI.Button (new Rect(200,200,100,100),"Button")){}
}
}
In this case for the same button I need two versions if the user has passed a texture or not. If I get dozens of buttons then it is all doubled. If I simply do:
public Texture2D background;
GUIStyle style = new GUIStyle();
void Start(){
if(background != null){
style.normal.background = background;
}
}
void OnGUI(){
if(GUI.Button (new Rect(200,200,100,100),"Button",style)){ }
}
And nothing is passed the button displays no default button shape. Is there a way to pass default values to the GUI style if none is provided by the user or am I doing wrong?
Cheers