- Home /
GUI text font change
I have this script running on my character (In JavaScript)for when i collect coins it'll add 5 points to my score. I have no idea how to change the Font of my GUI label?! Any Ideas??
var score = 0;
function OnTriggerEnter( hit : Collider){ if(hit.gameObject.tag == "Coin"){score += 5;Destroy(hit.gameObject);} }
function OnGUI () { GUI.Label (Rect (300, 25, 1000, 20), score.ToString()); }
Answer by GuyTidhar · Jun 28, 2011 at 02:55 PM
Create a GUISkin asset.
(right click menu in the project window -> GUISkin)
Within the create GUISkin look for "Label". Open "Label" and look for "Font" under it. Drag the font you wish to use into this field.
Now add the following line to the above script:
public var guiSkin : GUISkin;
Change your OnGUI function to this:
function OnGUI ()
{
GUI.skin = guiSkin;
GUI.Label (Rect (300, 25, 1000, 20), score.ToString());
}
Drag the GUISkin asset you have created onto the guiSkin field of the above script.
Now you should have the new font!
Thank you very much.. It doesn't seem to be working at the moment but I'll search for the problem (Possibly a font issue, made sure it was TTF). A GUISkin should come in handy..
Answer by Tim.Holman · Jun 28, 2011 at 02:56 PM
If you create a GUI skin, you can modify anything you'd like very easily. You'll just have to put a font style in your project folder first, then drag and drop it into the font variable in the GUI skin.
Answer by MasterBLB · Jun 28, 2011 at 03:09 PM
Well,to have own font you'll need such steps:
1.Put yourDesiredFont.tff into yourProjectFolder/Assets.More details there http://unity3d.com/support/documentation/Components/class-Font.html
2.As guyt says,create a GUISkin asset.
3.Click the GUISkin,and you see components like button,label,box etc that may be expanded.Expand component label and then you will see font options like Font(family),FontSize and FontStyle(bold etc)
Your answer
Follow this Question
Related Questions
Odd question... can a GUIText object be displayed upside-down? 2 Answers
Changing a GUILabel text SIZE 3 Answers
Why aren't asian fonts rendering dynamically? 0 Answers
Problem with GuiFont - Not appearing 0 Answers
Color.white not so much white... 3 Answers