1
\$\begingroup\$

So I've got a load menu using Unity's new UI system, basically just a list of save games you can select with a mouse click along with a couple of buttons at the bottom to delete or load the selected game file.

I've been disabling the Load Game and Delete Game buttons using the interactable attribute whenever a saved game item in the list is deselected:

deleteButton_LoadPanel.GetComponent<Button>().interactable = false;     
loadButton_LoadPanel.GetComponent<Button>().interactable = false;

This disables the buttons fine, but when I click on a saved game and then click a button, the deselect event for each save file is triggered BEFORE the onclick event for each button. This is no good.

If I have no deselection event for each individual save file I can click on each save file and then click the load or delete buttons and every thing works fine, but the buttons never get disabled which is not ideal.

My question is: How can I disable the buttons when an item is deselected, but still trigger the onclick event when they are selected? Are there any workarounds to this?

enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Any news about this @Mir? I am still struggling with this and don't want to implement and ugly code to do this. In my case the toggle group is not appropriate for my UI needs. Regards! \$\endgroup\$ – VicM Jul 7 '15 at 22:15
  • \$\begingroup\$ @VicM No, sorry. I gave up on it several months ago. Unity's UI controls don't seem to work correctly in terms of selection events right now. And you're right, toggle groups don't solve anything. I may take another look at it soon. \$\endgroup\$ – Mir Jul 7 '15 at 23:15
  • 1
    \$\begingroup\$ I ended up "solving" the problem using event and listeners. I was hesitant in doing so, because I need to trigger the event on each UI element I want to monitor so I can know which button was pressed to allow or not the click event. At the end I got the desired result but the solution is far from efficient. \$\endgroup\$ – VicM Jul 8 '15 at 16:54
1
\$\begingroup\$

Sounds like what you're looking for is more along the lines of a Toggle Group

A Toggle Group is not a visible UI control but rather a way to modify the behavior of a set of Toggles. Toggles that belong to the same group are constrained so that only one of them can switched on at a time - pressing one of them to switch it on automatically switches the others off.

This also requires that you use Toggles instead of Buttons.

The styling of the toggle can be made to match that of your buttons now.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ @mir Is this not what you're looking for? You've unaccepted this as the answer. \$\endgroup\$ – MichaelHouse May 31 '15 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.