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 /
avatar image
0
Question by fbic333 · Mar 06, 2014 at 05:09 AM · guistyletoolbargui-skin

Custom GUI Troubles -- Solved

Hello everyone, I am trying to make my health and score GUI look more custom than what Unity shows with GUI.Label and GUI.Box. I have been going through tutorials and the UnityGUI reference manual and learning alot on what to use to customize. I am guessing the problem is my script but I am at a loss. My script is kind of a mix up of a tutorial script and what I have learned with programming language. From the script, I am thinking I should get rid of GUISkin and replace it with GUIStyle or something else? Honestly I do not fully understand the GUI system after all the research and tutorial videos. I mean I understand what it is supposed to do but putting the programming behind it is kickin my butt.

Health and Score GUI script

 var customSkin : GUISkin;
 var healthIcon : Texture2D;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnGUI() 
 {
     GUI.skin = customSkin;
     var healthNumberName = PlayerCounters.playerHealth;
     var healthName = healthNumberName.ToString();
     var scoreNumberName = PlayerCounters.playerScore;
     var scoreName = scoreNumberName.ToString();
 
     GUI.Label(Rect(60,120,200,25), healthName);
     GUI.Label(Rect(90,120,200,25),scoreName);
     GUI.Box(Rect(20,60,100,90), healthIcon);
 }

Here is a screenshot of what it is showing with the toolbar script I have added below. alt text

Toolbar script I will customize as well but have not started or touched yet. This one is in C#

     private int toolbarInt = 0;
     private string[] toolbarStrings = new string[]{"Bullet", "Missile", "Land Mine"};
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnGUI()
     {
         toolbarInt = GUI.Toolbar (new Rect (25, 25, 250, 20), toolbarInt, toolbarStrings);
     }
 }

Any help or advice is greatly appreciated. I would greatly appreciate an explanation of what I have done wrong to help.

EDIT: also forgot to mention that when I try to get rid of the health texture I get problems. How do I get the box without any text or texture included?

worldguiscreenshot.png (9.0 kB)
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
0
Best Answer

Answer by whydoidoit · Mar 06, 2014 at 05:13 AM

Yeah well a GUISkin is just a bunch of standard GUIStyles - I tend to make up styles and use those because I find the skin editor clunky, but it depends really - it's fast for changing everything.

You can make a custom style for something in script by doing this:

   var myCustomButton = new GUIStyle("button");

Of course you can just make up some styles and assign them if you like.

Then you can mess with the font and the background etc. The backgrounds are stretched images if you set the "border" of the style - it makes it a 9 slice image where the number of pixels used for each cell are defined by the 4 border entries.

Comment
Add comment · Show 10 · 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 fbic333 · Mar 06, 2014 at 05:20 AM 0
Share

So adding "new" in front of GUIStyle it will show up on the inspector giving me the options to customize?

avatar image whydoidoit · Mar 06, 2014 at 05:21 AM 0
Share

So if you did this:

  public GUIStyle myButton;

It will be editable in the inspector - the other is for doing it from script (like you want to modify something explicitly).

avatar image fbic333 · Mar 06, 2014 at 05:33 AM 0
Share

Oh Ok I see now. Now I am thinking I need to redo my toolbar to make them as GUI.Button so I can customize. If not I am totally lost.

avatar image whydoidoit · Mar 06, 2014 at 05:35 AM 0
Share

You just have to pass your custom styles to each GUIxxx call.

avatar image fbic333 · Mar 06, 2014 at 05:44 AM 0
Share

Ok, stupid question but, how do I do that? With the top script, do I put it with the GUI.Label or GUI.Box? But I have no clue on the toolbar, I may just redo those in with the top script..

Show more comments

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUILayout Button as custom button from custom script 1 Answer

Cloning custom skin style 1 Answer

GUI.Toolbar with different images for each button using GUIStyle 1 Answer

copy a GUIStyle into a new GUIStyle var using JavaScript 2 Answers

Remove Button Border 3 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