Search Unity

Very strange Toggle Behaviour

Discussion in 'General Graphics' started by eco_bach, Mar 22, 2017.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Hi
    I'm using Toggle components as buttons in a ToggleGroup.

    Each Toggle is using a Sprite Swap Transition.

    I have just 2 states and Sprites. Selected and UnSelected.

    There are 3 Sprite slots with Sprite Swap Transition,

    1 Highlighted,

    2 Pressed, and

    3 Disabled.

    To properly show a Selected state you need to at least fill the Highlighted slot with your Selected Sprite.
    So I've done that and also filled the Pressed slot with my Selected Sprite as well.

    Simple enough.
    Everything works as it should, I can properly select each button and the Selected state for that Toggle button correctly appears, the remaining Togglebuttons in the same group properly show the UnSelected state or Sprite.

    However, with any ToggleButton selected, if I click ANYWHERE in my Game View, that ToggleButton reverts back to the UnSelected state., showing just the image defined in the Background component for the Toggle.

    Can anyone suggest what I am doing wrong?
    Another way of asking my question is how do you prevent Unity from deselecting the current Toggle when clicking anywhere in the GameView?
     
    Last edited: Mar 22, 2017
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    You need to swap the sprite via your own code. Toggle has a bool for when it is on. The other states are for default selectable behavior.
     
  3. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    ok thanks but if that is true, what is the purpose for the Toggle component having Sprite Swap transition states? Just seems very strange to me...