• 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 TomaszKielski · Apr 29, 2011 at 01:24 PM · deselectoption

GUI.Toolbar with deselect option

Is there a simple way to create the GUI.Toolbar with deselect option, so that clicking a selected button would deselect it and set the .selected index to -1 or similar?

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

3 Replies

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

Answer by Kourosh · Apr 29, 2011 at 01:51 PM

Try this one:

var toolbarInt : int = -1; var lastbarInt : int; var toolbarStrings : String[] = ["Toolbar1", "Toolbar2", "Toolbar3"];

function OnGUI () { toolbarInt = GUI.Toolbar (Rect (25, 25, 250, 30), toolbarInt, toolbarStrings); if(GUI.changed){ if(lastbarInt == toolbarInt){ toolbarInt = -1; } lastbarInt = toolbarInt; } }

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 TomaszKielski · Apr 29, 2011 at 02:01 PM 0
Share

Thanks. Almost the same as I've created myself, but mine was missing the condition (GUI.changed) and that is probably why it was not working as expected.

avatar image
1

Answer by Siegeon · Apr 29, 2011 at 01:53 PM

Sure, you could have a button that sets a bool such as Toolbar active. Then in your on GUI method check the bool before drawing the tool bar

Code untested.

public class GUIManager : MonoBehaviour{
private bool toolbarActive;
void OnGUI()
{
    //show the topmost menu if we have one
    if (toolbarActive())
    {
        //Draw your toolbar here
    }
    //this would be the button control separate from your toolbar
    if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture))
       toolbarActive = !toolbarActive;
}
}

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 Uzquiano · Apr 29, 2011 at 01:39 PM

You must code it by yourself, or try to search in the wiki

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Unity Editor deselects item after clicking on its controls. 4 Answers

Make Dropdown option non-interactable 2 Answers

How to use the deselect Event Trigger? 1 Answer

Set Generate Lightmap UVs on All Assets 0 Answers

How do I prevent Unity from deselecting the current object when I click in the SceneView? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges