Search Unity

Multiple Active Toggles in a Toggle Group?

Discussion in 'UGUI & TextMesh Pro' started by unity_uT2X6HlVKogv2g, Jan 20, 2018.

  1. unity_uT2X6HlVKogv2g

    unity_uT2X6HlVKogv2g

    Joined:
    Jan 11, 2018
    Posts:
    2
    A friend of mine and I are working on a little UI project in Unity.

    I'm handling most of the scripting and I've hit a road block working with toggles.

    What we have is a set of eight toggles and a user should only be able to select two of them at a time. The functionality should be similar to a toggle group, either deselecting the oldest selected toggle or just preventing the user from selecting additional toggles.

    Of course you can only have a single toggle selected in a toggle group at a time which is where the problem comes in. I'm having a hard time trying to figure out how I can code anything that will allow for a specific number of toggles to be selected.

    How the user is prevented from selecting more toggles isn't particularly important -- though if anyone could provide examples of both deactivating the remaining toggles and deselecting the oldest selected toggle (dequeue?) would be much appreciated -- so much as getting an example of how to impose the restriction.

    Any help anyone can provide would be much appreciated, thank you!
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Why not just ditch the toggle group & create your own code for what you want..
    You've pretty much described what you want.

    Keep track of the toggles in a list, and the count.
    If the count exceeds 2, toggle off the oldest one, move the (old newest) to the oldest, and the current to the newest.

    Try to write something up like that, and if you get stuck, post your script here and maybe someone can assist you further. :)
     
    mr_blahblah, bigChris and fenskebawb like this.
  3. unity_uT2X6HlVKogv2g

    unity_uT2X6HlVKogv2g

    Joined:
    Jan 11, 2018
    Posts:
    2
    That is actually exactly what I ended up doing. Heh, I guess I just needed to write out the problem to get a better grip on it.

    I put together some custom code and it's all working now. Took me a bit,but I think I'm good!
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Cool, glad ya got it working :)
     
  5. palalopea

    palalopea

    Joined:
    Dec 4, 2017
    Posts:
    3
    how to create multiple toggle in toggle group? because I created just once checked only.
     
  6. MasterDiscord

    MasterDiscord

    Joined:
    Oct 21, 2018
    Posts:
    1
    I'm actually currently trying to do the same thing and i'm fairly new to this. could you show me the script you wrote to not let more than a certain number of toggles be active at once? the reason i ask is cuz nowhere on the internet can i find anyone explaining how to limit the number of toggles that can be active at once besides using a toggle group, but i don't want it to be limited to 1. i want the limit to be 3.
     
    cponidjem likes this.