• 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 /
avatar image
0
Question by Cerbion · May 23, 2012 at 01:50 AM · javascriptguihudguistylealignment

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

Comment
Add comment
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

1 Reply

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

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.

Comment
Add comment · Show 1 · 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 Cerbion · May 23, 2012 at 05:42 AM 0
Share

Thanks! That was really helpful, and now my HUD looks even better then before! :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Inventory Help 0 Answers

Cameras Switch Based On Button Click 1 Answer

Why is texture blurred in one GuiStyle and not in another? 1 Answer

Whats wrong with my GUI.Toggle? 2 Answers

How can I change text alignment for GUI? 1 Answer


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