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 $$anonymous$$ · Dec 20, 2014 at 11:47 PM · guitexturebutton

Changing one button style's background changes for all styles

In the code below I am trying to have different styles for different buttons. The handStyle GUIStyle is used for cards that should be shown and blankHandStyle for cards that should give the appearance of being upside down. When I remove the last line all buttons show the handStyle GUIStyle, when it is there all buttons show the cardBack texture. When creating buttons in the OnGUI function I have correctly assigned Styles in the parameters.

         //Hand
         handStyle = GUI.skin.GetStyle("button");
         handStyle.normal.background = normalButton;
         handStyle.fontSize = Mathf.RoundToInt(((Screen.width/Screen.height)*11.5f)*GUIScale);
         blankHandStyle = GUI.skin.GetStyle("button");
         blankHandStyle.normal.background = cardBack as Texture2D;
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

2 Replies

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

Answer by shriya · Dec 23, 2014 at 08:10 AM

Hi,

Problem here is that you are passing button style to both handStyle and blankhandstyle which is why changing the background of one changes for all. You need to create two different custom styles and and pass them to hand style and blankHandStyle separatly ,then it would not affect each other. Hope you are clear what i mean.

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 $$anonymous$$ · Dec 23, 2014 at 03:23 PM 0
Share

I had forgot to come back and amend this, I apologize, this was the answer. I wasn't aware that by using the GetStyle function that it meant when you changed it in a variable it would change the default style as well. Thank you.

avatar image
2

Answer by salvador007 · Dec 23, 2014 at 10:17 AM

Here you need to pass different styles to both the buttons. You can achieve this by creating a GUISKIN and then making custom styles as much as you want.

You can take help from below:

alt text

Now in Code assign this GUISKIN publically.

C# code:

 public GUISkin mainMenuSkin;
 and then
 
 handStyle = mainMenuSkin.GetStyle("CustomStyle1");
 blankHandStyle = mainMenuSkin.GetStyle("CustomStyle2");
 
 so on..


screen shot 2014-12-23 at 3.36.26 pm.png (39.1 kB)
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

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

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

Related Questions

GUI button doesn't appear on Android 0 Answers

How can I get the Unity 3 texture for 'button on'? 2 Answers

Specify OnMouseEnter 2 Answers

Making texture cover whole button 1 Answer

DrawTexture GUI iPhone 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