- Home /
GUI.Label font change ?
Hi im trying to change the arial font to a different one for my GUI.Label but having zero luck :( I have seen lots of different answers to this problem but none seem to work can anyone give me a clue please ,sorry I am the JavaNoob :)
function OnGUI(){
var font : Raptor_Sans_font_by_rotweiler83;
GUI.Label (Rect (400,120,110,100), "Checkpoint : " + ckp); GUI.Label (Rect (340,10,110,100), "Laps" + lap);
gives me this :(
Assets/Checkpoint.js(27,12): BCE0018: The name 'Raptor_Sans_font_by_rotweiler83' does not denote a valid type ('not found').
Very roughly, you first have to import the True Type font into your Assets (Project window.) It has to be a TypeType (ttf.)
Then you declare a GUIStyle (a GUISkin is a nice way to combine lots of these, but you don't have lots yet) and add the font to the GUISyle in the Inspector.
Finally, and this is in the man pages, sort of, add it as the last input: `GUI.Label(Rect(...),"Lap 8",G);` I'm pretending you declared it as G.
Answer by T27M · Sep 24, 2012 at 03:55 PM
Check out the GUISkin tutorial.
This is also good if your wanting to know more.
var MenuSkin : GUISkin;
function OnGUI ()
{
GUI.skin = MenuSkin;
}
Create a GUI skin ,Assets > Create > GuiSkin. Create that script and drag the it onto the camera object , assign a font in the inspector to the skin you just created. Drag your new GUI skin onto the MenuSkin value on the camera in the inspector. That should be it.
$$anonymous$$y guilabel is in my checkpoint script ,should I add the code to that and drag the guiskin also to that ?
Just add a new label underneath where i declared the GUI.skin. Well to test it works. If not you have done something wrong.
function OnGUI(){
var $$anonymous$$enuSkin : GUISkin; GUI.skin = $$anonymous$$enuSkin;
GUI.Label (Rect (400,120,110,100), "Checkpoint : " + ckp); GUI.Label (Rect (340,10,110,100), "Laps" + lap); GUI.Label (Rect (540,10,400,20), "Laptime 1 : " + lapTime1); GUI.Label (Rect (540,30,400,20), "Laptime 2 : " + lapTime2); GUI.Label (Rect (540,50,400,20), "Laptime 3 : " + lapTime3); GUI.Label (Rect (540,70,400,20), "Laptime 4 : " + lapTime4); GUI.Label (Rect (540,90,400,20), "Laptime 5 : " + lapTime5);
if (lap==5) GUI.Label (Rect (540,200,200,100), "You WON !");
}
I have called the Guiskin $$anonymous$$enuSkin in the inspector ,where do i put the label please? sorry my brain is fried lol :) to be honest I am lost at the new label part ;o
var $$anonymous$$enuSkin : GUIS$$anonymous$$in; Needs to be above OnGUI(), See my code above
Answer by john-essy · Sep 24, 2012 at 07:24 PM
Ok to change font by code all you need to do it create a var
var font : Font
then within Start() or Awake()
do something like this
guiText.font = font;
This will change your current font to you new font.
Just make sure that you pull a font onto the variable
Even still if you have a GUISkin all you need to do is assign some new font to it then it will work.
ok fried brain is asking one of you guys to insert this into the code above lol ,because im still failing
var font : Arial.ttf
guiText.font = Arial.ttf;
like this obviously different font but do i need the ttf extention ?
Your answer
Follow this Question
Related Questions
GUI Label Width & Height 0 Answers
Android OnGUI Font size problem. 0 Answers
Cropped Label Problem - Big Font - Unity3D 1 Answer
How to find a font via script? 2 Answers
Is there a way to measure the pixel with/height of a string with a given font? 2 Answers