Reputation:
Okay this may be really simple, but every attempt I make the console throws up various errors. If i have if(GUI.Button(new Rect(x, y, Screen.width, z), "play")) {
How would I go about changing the size of the text. I have a custom GuiSkin used on the text, but I'm unsure how to change the font size of the text without using the inspector - I am using unity. What I am trying to do is change the font size depending on the screen resolution.
Upvotes: 0
Views: 2192
Reputation: 765
If you have create your GUiSkin object, first you can using inspector to change GuiSkin.Button.FontSize. Then apply this setting in you button.
public GUISkin yourGuiSkinObject;
void OnGUI()
{
if(GUI.Button(new Rect(0, 0, 100, 20), "Test", yourGuiSkinObject.button))
{
//Do something.
}
}
Second you can using script to change fontSize. And change the size depend on the screen's height.
public GUISkin yourGuiSkinObject;
void Start()
{
int scale = Screen.height / 20;
yourGuiSkinObject.button.fontsize = scale;
}
void OnGui()
{
if(GUI.Button(new Rect(0, 0, 100, 20), "Test", yourGuiSkinObject.button))
{
}
}
Upvotes: 1