- Home /
Changing background, font and style of buttons
i am developing a GUI for my game, but i cannot find any way of changing my background(putting a custom image), also when i am trying to change the font and style of a button text the button border is disappearing, please help
Answer by TonyLi · Jul 16, 2013 at 12:42 AM
Unity's GUI Skin page has lots of good info.
For the background, you can use:
GUI.Label(new Rect(0, 0, Screen.width, Screen.height), customImage);
to put a custom image on the screen. You can play around with GUI.Label's GUIStyle options to position and scale it as you want.
Regarding buttons, it sounds like you're losing the background image. You can get the default GUI textures from here and reassign them, or assign them to custom styles you create.
There are also commercial tools like Unity GUI Helper that could make it much easier.
And here's a tutorial on creating custom GUISkins: http://forum.unity3d.com/threads/113055-Creating-Custom-GUI-Skins-PART-ONE
/* Example level loader */
var username : String = "";
var password : String = "";
var title : GUIStyle;
var test : GUIStyle;
//var skin1 : GUIContent;
var img : Texture;
// JavaScript
function OnGUI () {
GUI.Label(Rect(0,0,Screen.width,Screen.height),GUIContent(img));
GUI.Label(Rect(10,5,500,100),"INFINITY FORCE",title);
if (GUI.Button (Rect (10,125,150,100), "START",test))
{
Application.LoadLevel (1);
}
if (GUI.Button (Rect (10,235,150,100), "OPTIONS"))
{
Application.LoadLevel (2);
}
if (GUI.Button (Rect (10,345,150,100), "CUSTO$$anonymous$$IZE!"))
{
Application.LoadLevel (2);
}
if (GUI.Button (Rect (10,455,150,100), "QUIT"))
{
Application.LoadLevel (2);
}
GUI.Label(Rect(1000,150,100,50),"USERNA$$anonymous$$E");
GUI.Label(Rect(1000,200,100,50),"PASSWORD");
username = GUI.TextField(Rect(1110,150,200,30),username,25);
password = GUI.PasswordField(Rect(1110,200,200,30),password,25);
}
this is my code that i wrote the background image is not covering the whole screen, and the start button that i wanna customize(font and all), for that i used the test variable but the START button itself is dissappearing.][1]
Your answer
Follow this Question
Related Questions
How can I prevent my GUI background texture from getting pixelated or stretched? 1 Answer
GUIStyle not working on GUI.Button 4 Answers
Can change the shape of a GUI button/box/label to fit the shape of an object? 1 Answer
Unity Preferences' Large Heading Font 2 Answers
How to place/add a HD image/picture in background of my game? 0 Answers