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 TheDividedSegment · Dec 13, 2014 at 07:39 AM · boxselectmakingdeselectcustom-class

How can I set the GUI box to deselect after another one is selected?

I am making a simple character customization and I have run into a problem where both boxes are selected for both classes and it will create both classes. How can I make it so that one when box is selected, it will automatically deselect the other box?

 void OnGUI() {
         isMageClass = GUILayout.Toggle (isMageClass, "Mage Class");
         isWarriorClass = GUILayout.Toggle (isWarriorClass, "Warrior Class");
         if (GUILayout.Button("Create")) {
             if(isMageClass){
                 newPlayer.PlayerClass = new BaseMageClass();
         } else if (isWarriorClass) {
                 newPlayer.PlayerClass = new BaseWarriorClass();
 
         }
        }

This is what I have for the character selection.

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
0
Best Answer

Answer by Kiwasi · Dec 13, 2014 at 07:41 AM

Are you version constrained? Upgrading to 4.6 and using the new UI tools would make this a trivial task.

Edit: If you are version constrained then you are probably better off using an Enum. Loop through the values to create each button in OnGUI. As enums can only have one value set then by definition the group will toggle naturally. It also makes things more extendible. Let me know if you want to go down this path and I will mock up some pseudo code.

Comment
Add comment · Show 3 · 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 TheDividedSegment · Dec 13, 2014 at 07:02 PM 0
Share

If you don't $$anonymous$$d, I would like to see an example

avatar image Kiwasi · Dec 15, 2014 at 06:33 AM 0
Share

Sure. Totally untested pseudo code.

 enum CharacterClass {Wizard, Orc, Dragon, Tiger};
 CharacterClass selectedCharacter;
 
 void OnGUI {
     foreach (CharacterClass value in Enum.GetValues(typeof(CharacterClass))) {
         if(GUILayout.Toggle (value == selectedCharacter, value.ToString() + " Class")){
             selectedCharacter = value;
         }
     }
 }

There are probably a few errors in there. But once you get it to compile it should make a nice toggle for you.

avatar image TheDividedSegment · Dec 17, 2014 at 03:25 AM 0
Share
 enum ButtonPressed {Info, Stat};
     ButtonPressed selectedButton;
 
 
     void OnGUI() {
 
 
         foreach (ButtonPressed value in enum.ButtonPressed(typeof(ButtonPressed))) {
             if(GUILayout.Toggle (value == selectedButton, value.ToString() + " Class")){
                 selectedButton = value;
             }
         }
    }


I changed some stuff around but the error I originally got was from "enum.ButtonPressed" saying "Unexpected Symbol 'enum'" and I am clueless because I have tried multiple solutions. The original one you gave me saying "Enum.GetValues" gave me the same error.

EDIT: I figured it out, thanks for the help.

avatar image
1

Answer by Wizardman290 · Dec 13, 2014 at 08:06 AM

Try making a boolean of some sort, like

 if(isMageClass){
    YourBool = true;
 }
 if(isWarriorClass){
    YourBool = false;
 }

Then just use this to make one selected, if the other is false. Like WarriorClass is only active if YourBool is false or something, just something like that.

If this is nothing like your were asking I'm sorry, i am new to programming/coding/whatever, i am just trying to help. Sorry if I was not useful at all lol.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to change selected button in EventSystem or deselect it 5 Answers

Select Deselct a GameObject 1 Answer

(C#) Clicking on gameObject to select, clicking off to deselect 3 Answers

how to select and deselct an instantiated objects. 3 Answers

Deselect a selected object? 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