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 tw1st3d · Jul 10, 2013 at 03:10 PM · c#buttoncolorchangemultiple

Multiple Button Modifications

Hey guys, so I'm working with a load screen, where someone can select one of 30 save games.

 foreach(var i in text)
 {
     if(GUI.Button(new Rect(0, y, 376, 20), i, "LoadLine"))
     {
         LoadSkin.button.font.material.color = Color.yellow;
         if(loadGame == i.ToString()){
             //Load Game
         }else{
             loadGame = i.ToString();
             Debug.Log("Trying to load: " + i.ToString());
         }
         Debug.Log(loadGame);
     }
     y = y + 20;
 }

How am I able to change the font color of the button they click?

 LoadSkin.button.font.material.color = Color.yellow;

throws a null pointer exception. Any ideas? Should I be using something other than a button?

Comment
Add comment · Show 3
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 tw1st3d · Jul 10, 2013 at 07:27 PM 0
Share

Reviving.

avatar image tw1st3d · Jul 10, 2013 at 11:35 PM 0
Share

If anyone has any idea on what I need to do, I would be eternally grateful.

avatar image Jonathon82931 · Jul 10, 2013 at 11:56 PM 0
Share

I can show you the script I found on youtube for changing 3d text but I am not certain it will help you using c# using UnityEngine; using System.Collections; public class StartGameScript : $$anonymous$$onoBehaviour { void On$$anonymous$$ouseEnter() { gameObject.renderer.material.color = Color.blue; } void On$$anonymous$$ouseExit() { gameObject.renderer.material.color = Color.white; } void On$$anonymous$$ouseDown() { Application.Quit(); } } what the script dose is change 3d text mesh color and quit.

2 Replies

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

Answer by Jamora · Jul 11, 2013 at 12:08 AM

You need to change the "Active" setting in your GUISkin's custom style to whatever color you want when the user clicks on the button. Apparently the background texture can not be "None", or it won't work.

If you want to permanently change the text color of the button the user has clicked on, store the buttons that have been pressed, then create a different style for pressed buttons, which is chosen if the button has been pressed.

 foreach (string i in text) {
             if(nextButtonAlreadyPressed){
                 if(GUI.Button(new Rect(0, y, 376, 20), i, "LoadLinePressed")){
                     ButtonFunction();}
             }else if(GUI.Button(new Rect(0, y, 376, 20), i, "LoadLine")){
                     ButtonFunction();
             } 
             y = y + 20;
         }        
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 tw1st3d · Jul 11, 2013 at 12:21 AM 0
Share

Adding in that extra LoadLinePressed worked perfectly! Thank you very much.

avatar image
0

Answer by Yokimato · Jul 11, 2013 at 12:00 AM

 foreach(var i in text)
 {
     GUI.color = your_color_here; //<--- SET COLOR BEFORE DRAW
     if(GUI.Button(new Rect(0, y, 376, 20), i, "LoadLine"))
     {
        LoadSkin.button.font.material.color = Color.yellow;
        if(loadGame == i.ToString()){
          //Load Game
        }else{
          loadGame = i.ToString();
          Debug.Log("Trying to load: " + i.ToString());
        }
        Debug.Log(loadGame);
     }
     GUI.color = default_color_here; //<-- Don't forget to revert it afterwards
     y = y + 20;
 }
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 tw1st3d · Jul 11, 2013 at 12:05 AM 0
Share

Unfortunately, that didn't do what I wanted it to. I want it to change the font color of --ONLY-- the button that is clicked, not all of them.

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

17 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

Related Questions

UI Button color 1 Answer

Blend into next color instead of jumping to next color 1 Answer

Trying to change the color of a game object. 1 Answer

Distribute terrain in zones 3 Answers

Referencing color change when object is 'deselected' 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