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();
}
}
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.
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.