Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 The_Unity_Game_Developer · Oct 29, 2014 at 09:41 PM · green

Button that changes a colour.

So I understand that I just asked for how to store a GUI colour in a variable, but I couldn't get it to work in the way I needed it to.

I wanted a button that changes it's colour if you click on it. Here's what I tried:

 function OnGUI () {
 GUI.color = Color.green;
 var colourGreen : Color = GUI.color;
 
 if(GUI.Button(Rect(Screen.width/1.8, Screen.height/1.8, 100, 50), "Green"))
     {
     colourGreen = true;        
     }
 
 }

Unfortunately this just changes the button from the start. Also, this should work for all of the buttons I have. I just used one button so that it would shorten the question. Hehe!

I understand that this should return an error, but I hope that you all understand what I'm trying to do, so if anybody knows how I can do this, then please show me in the answers section! Thanks!

Comment
Add comment · Show 5
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 The_Unity_Game_Developer · Oct 29, 2014 at 07:53 PM 0
Share

Thank you for the answer, and I have kept it in $$anonymous$$d. However, I have taken some coding tutorials for JavaScript and I have a good knowledge of GUI stuff and more in unity coding. I just can't get around some problems every once in a while, and I come here for help because my school is relying on me to build a good game that they can learn from in ICT. I just need help with a couple of things. All I'm asking for is a little help with the script I have now... please...

avatar image Habitablaba · Oct 29, 2014 at 07:58 PM 1
Share

The problem, though, is that you are asking for help with things that are at the very fundamental level of program$$anonymous$$g. Not just Unity program$$anonymous$$g, or Java Script program$$anonymous$$g, but generic program$$anonymous$$g concepts.
You are currently struggling with how to set a property on an object, for example. Assignment of values to variables is one of the (if not the) most basic of concepts in any language.
Beyond that, your question touches on concepts related to statics and conditional statements, both of which should be covered early on in any set of tutorials or lessons.

avatar image The_Unity_Game_Developer · Oct 29, 2014 at 08:00 PM 0
Share

I truly apologise about this. However it isn't the variables that I'm struggling with. It's applying it to the GUI Button as I need it. I promise. An answer to this, and I'm gone. Please, I promise...

avatar image The_Unity_Game_Developer · Oct 29, 2014 at 08:35 PM 0
Share

I understand that my knowledge is limited, but my game has gone well so far. All I'm asking for is a little bit of help with this one bit, then I'm gone. I swear, I just need help. Just one script, or guidance on how to use the script. I know how it works I just can't figure out how to put it in a script.

avatar image The_Unity_Game_Developer · Oct 29, 2014 at 09:19 PM 1
Share

Hmm... Ok. Thanks so much! After reading that comment I was able to piece together a system for my game that allows the user to choose from a variety of colours to colour there GUI. Also, I admit that my knowledge is limited. I know that. However I was able to think of a good custom system for the menu itself after just getting my question closed three times. But my friend. You have been incredibly helpful. Thank you!

1 Reply

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

Answer by FreeTimeDev · Oct 30, 2014 at 01:45 AM

Make another button.

Let's say you have your default and not selected button -- let's call this button A.

When user clicks button A, replace it with button B. Button B will be green/red/blue or what ever you want. Note the bool bIsGreen.

 if(!bIsGreen) //if bIsGreen is false...
 {
 if(GUI.Button(Rect(Screen.width/1.8, Screen.height/1.8, 100, 50), "Not Green")) //and you click a button
      {
      colourGreen = true;   //make it green!
      bIsGreen = !bIsGreen
      }
 }else{ //...else (if we are green already)
 if(GUI.Button(Rect(Screen.width/1.8, Screen.height/1.8, 100, 50), "Green")) 
      {
      colourGreen = false;   //make it not green!
      bIsGreen = !bIsGreen
      }
 }
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 The_Unity_Game_Developer · Oct 30, 2014 at 09:45 AM 0
Share

Thanks! I've been able to use that help and previous help and I've made a custom script!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

UnityEngine.Input.GetMouseButton(1)) issue 1 Answer

I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer

How would I play a sound in a certain range of an object? 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