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 chris200x9 · Jun 01, 2014 at 09:49 PM · guibuttonguiskin

gui button custom skin not applying background

 void OnGUI()
     {
         if (Input.GetKey(KeyCode.UpArrow))
            {
             GUI.skin = guiSkin;
 
                 float xpos = transform.position.x;
                 float ypos = transform.position.y;
                 Rect position = new Rect( xpos, 150 + ypos , 53 * 2, 87);
                 DrawQuad(position,Color.red);
             GUI.backgroundColor = Color.clear;
             GUI.SetNextControlName("1");
             GUI.Button(new Rect(xpos, 150 + ypos, 53, 87), "", "button1");
             if(Input.GetKey(KeyCode.RightArrow))
                {
                 GUI.FocusControl("1");
                 //GUI.Button(new Rect(620 + xpos, 150 + ypos, 53, 87), guiSkin.focused.background);
                 //Debug.Log("true");
                }
            }
 
         }

I have a custom gui skin that is hooked up through the inspector with an element named button1 that I am trying to display with the line

GUI.Button(new Rect(xpos, 150 + ypos, 53, 87), "", "button1");

but nothing shows up. However if I put "hi" or something as the text the hi shows up so it is being called button1 is just not showing up, I am receiving to errors or warnings so it "sees" button1 but it's just not showing.

edit: I have played around with colors on the text and I can confirm it's calling the button1 style but it's not displaying the background image, any help?

Comment
Add comment · Show 2
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 entropicjoey1 · Jun 02, 2014 at 12:05 AM 0
Share

if button1 is a variable try removing the quotation

avatar image chris200x9 · Jun 02, 2014 at 12:20 PM 0
Share

That errors, it's not a variable it's the name of the custom styles element. I have played around with text and defining colors in the style for normal, active, etc. The code works it's just not displaying the background image and it's really got me stumped.

2 Replies

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

Answer by chris200x9 · Jun 02, 2014 at 03:45 PM

Turns out this line was the culprit:

GUI.backgroundColor = Color.clear;

I was turning the background image clear.

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

Answer by TrickyHandz · Jun 02, 2014 at 12:43 PM

For the custom style to show properly without having a reference stored in a variable you need to change the button declaration to include a look up for the style. SO this line:

 GUI.Button(new Rect(xpos, 150 + ypos, 53, 87), "", "button1");

Should look like this:

 GUI.Button(new Rect(xpos, 150 + ypos, 53, 87), "", guiskin.FindStyle("button1"));
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 chris200x9 · Jun 02, 2014 at 12:53 PM 0
Share

Just tried and both lines work exactly the same. Text works, changing colors according to the style with respect to normal, active, etc is fine. I really don't know what's wrong the code works in all respects except it does not show the background image.

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

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

Related Questions

GUISkin or otherwise - Once clicked, button stays same color 1 Answer

Unable to find style in skin repaint 1 Answer

Whats wrong with my GUI.Toggle? 2 Answers

How to attach GUI Skin on button? 0 Answers

GUISkin is overlaying my button image 0 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