- Home /
Customize a scripted GUI
Hey guys, I am currently programming a FPS with Unity3D, using Javascript and C#. What bothers me is that the Built-in GUI from Unity is not like I want it, and since I am not that experienced in Unity, i am asking for a little bit of help (should be actually very easily to solve).
Here is the code: (UnityScript)
function OnGUI()
{
GUI.Box(Rect(198,Screen.height-50,100,24), ""+Bullets+" | "+TotalBullets);
}
It is actually working well, but I want to change the alignment (and color/font/font-size), and I don't know how do to that, and do not send me to the Unity Script Reference, cause I went there and I tried a little bit, but nothing worked actually (I obviously used it incorrectly, because I know it actually works.)
However would be nice if you can tell me how I can create a (i think it was called that way) GUIStyle or something like this, to solve my problem :)
Greets, Cerbion
Answer by Bunny83 · May 23, 2012 at 02:00 AM
Create a GUISkin and drag it to the variable of this script:
var skin : GUISkin;
function OnGUI()
{
GUI.skin = skin;
GUI.Box(Rect(198,Screen.height-50,100,24), ""+Bullets+" | "+TotalBullets);
}
In your GUISkin you can also define as much custom styles you want. To use a custom style, just use the name you've given the style
var skin : GUISkin;
function OnGUI()
{
GUI.skin = skin;
GUI.Box(Rect(198,Screen.height-50,100,24), ""+Bullets+" | "+TotalBullets, "myCustomeStyle");
}
GUIStyles works similar to CSS on websites. There are too many things you can do with it. You just have to play around and read the documentation. Keep in mind that you can change any settings while you test your game / GUI in the editor.
Thanks! That was really helpful, and now my HUD looks even better then before! :)
Your answer
Follow this Question
Related Questions
Sometimes the GUI selectively doesn't render some letters 1 Answer
CoolDown Animation on the GUI 1 Answer
Odd question... can a GUIText object be displayed upside-down? 2 Answers
Off Screen direction indicator HUD element / wrestling with Quaternion 1 Answer
Using GUISkin with Hierachy Objects 0 Answers