Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by javanoob · Sep 24, 2012 at 03:08 PM · fontonguigui.label

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').

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Sep 24, 2012 at 07:38 PM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image javanoob · Sep 24, 2012 at 06:46 PM 0
Share

$$anonymous$$y guilabel is in my checkpoint script ,should I add the code to that and drag the guiskin also to that ?

avatar image T27M · Sep 24, 2012 at 06:49 PM 0
Share

Just add a new label underneath where i declared the GUI.skin. Well to test it works. If not you have done something wrong.

avatar image javanoob · Sep 24, 2012 at 06:53 PM 0
Share

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

avatar image T27M · Sep 24, 2012 at 06:58 PM 0
Share

var $$anonymous$$enuSkin : GUIS$$anonymous$$in; Needs to be above OnGUI(), See my code above

avatar image T27M · Sep 24, 2012 at 07:03 PM 0
Share

http://imageshack.us/g/1/9777436/

avatar image
0

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image john-essy · Sep 24, 2012 at 07:27 PM 0
Share

Even still if you have a GUISkin all you need to do is assign some new font to it then it will work.

avatar image javanoob · Sep 24, 2012 at 07:33 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges