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
2
Question by Sacristan · Mar 31, 2011 at 12:41 PM · buttonhighlightpressed

Highlighting pressed button

Ive got problem: I want to hightlight button if it has been pressed, there are meant to be many buttons and one button represents a tool, so if a button is pressed then tool is selected... I just want to highlight one button, that has been selected. If one button is selected (highlighted) then other buttons cant be selected(highlighted)

Ive added a code, that doesnt work, but will say what i meant with all this....

if(GUI.Button (Rect (10,200,unactiveb, unactiveb),touch))
{
    targetScript.SetTool("touch");
    GUI.Button (Rect (10,200,activeb, activeb),touch);
}
else GUI.Button (Rect (10,200,unactiveb, unactiveb),touch);

Hoping for Your answers and solutions to this problem.

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

5 Replies

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

Answer by efge · Mar 31, 2011 at 01:27 PM

You could use GUIStyles. You can set the background image and text colors for the states Normal, Hover, Active and Focused (among others).

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 Joshua · Mar 31, 2011 at 03:04 PM 0
Share

I admit this option is $$anonymous$$UCH better if you have loads of buttons and want an uniform style. In my opinion my solution is nicer if you have only a few and want maximum freedom to toggle and adjust and immediately see the changes.

avatar image
1
Best Answer

Answer by Joshua · Mar 31, 2011 at 01:45 PM

I just use this script on all my buttons.Just create a guiTexture and add this script. It allows me to change size when I mouse over, change color/texture when it's selected and it allow me to expose all those variables so I can freely toggle them in my editor. If you don't want to toggle color but texture replace guiTexture.color with guiTexture.texture.

var normalColor : Color; var overColor : Color; var selectedColor : Color; var selectedOverColor : Color; var size : int var overSize : int private var selected : boolean = false; function Start () { guiTexture.color = normalColor; guiTexture.pixelInset.width = size; guiTexture.pixelInset.height = size; selected = false; } function OnMouseEnter () { if(selected){ guiTexture.color = selectedOverColor; } else if(!selected){ guiTexture.color = overColor; } guiTexture.pixelInset.width = overSize; guiTexture.pixelInset.height = overSize; } function OnMouseExit () { if (!selected) { guiTexture.color = normalColor; }

 else if (selected) {
     guiTexture.color = selectedColor;
 }
 guiTexture.pixelInset.width = size;
 guiTexture.pixelInset.height = size;

} function OnMouseDown () { if (!selected) { selected = true; guiTexture.color = selectedColor; }

 else if (selected) {
     selected = false;
     guiTexture.color = normalColor;
 }

}

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 Sacristan · Mar 31, 2011 at 02:20 PM 0
Share

Thanks for support!

avatar image
1

Answer by Ray-Pendergraph · Mar 31, 2011 at 01:27 PM

Use a GUI.Toggle but style it like a button. This will utilize the skin to differentiate the selected button(s) from the unselected ones and the toggle supports the behavior for what you want. You will want to keep the state of each button in an array or dictionary(with something that identifies the tool) so you know which buttons are selected.

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
-1

Answer by ChupO · May 08, 2011 at 02:15 PM

This is really easier to do... It's in JavaScript. Script:

function OnMouseEnter() { //Change text color into green renderer.material.color = Color.green; }

function OnMouseExit() { //Change text color back into white renderer.material.color = Color.white; }

This is code to change white color into green by mouse over-it and reversed.......

I hope I understood the question and helped...

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 RyanWittbs · Nov 14, 2013 at 01:08 AM

For anyone who needs a very quick & simple solution, check out the GUI toolbar

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

1 Person is following this question.

avatar image

Related Questions

Disable a GUI while left mouse button is Down? 2 Answers

4.6 UI Button Press, how? 2 Answers

Playing a button pressed animation on a box 1 Answer

How to make a menu controled from Keyboard and using buttons? 0 Answers

UI button pressed animation not playing directly after entering 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