Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

UI Toggle no relation between graphics and state

Discussion in 'UGUI & TextMesh Pro' started by UltiPangol, Nov 23, 2019.

  1. UltiPangol

    UltiPangol

    Joined:
    Nov 12, 2019
    Posts:
    4
    Hello, firstly I want to clarify that English is not my first language and I'm not sure to post in the right place, being new to this forum.

    I am trying to select a line in a list (ScrollView) by clicking on it in order to apply an action on the selected line.

    So I add a Toggle Component to the Prefab that is added to each line in order to activate it.

    When I click on it, the hue changes according to the settings I specified and the state goes from Off to On.
    So far so good.

    But when I click elsewhere on the screen, the line is no longer selected because the hue returns to normal, but the state does not change.
    And if I click on another line, same thing.
    The new Line is selected and its status changes to On, but the previous line remains On.

    I just want to be able to select an item from the list, then click another button outside this list to call an action on the selected item.

    What is the right method?

    Here is my Toggle Component settings :

    upload_2019-11-23_16-10-21.png

    Thank you in advance for your answers.
     
  2. UltiPangol

    UltiPangol

    Joined:
    Nov 12, 2019
    Posts:
    4
    Well, apparently the graphical changes offered with the Toggle Component are only handled by the event system and have nothing to do with the state of the Toggle.
    So I put "None" for the transition and have visual edit by hand via script.
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,835
    A Toggle's on/off state is shown graphically by turning on and off the graphic specified in the "Graphic" field (near the bottom of the Toggle's properties), which you have set to "none" in your screenshot. When you ask Unity to create a Toggle, the standard model comes with a check mark that is turned on and off.

    The "Transition" works the same for a Toggle as it does for a Button--it's there to make it look more reactive to the mouse, or show what control is currently selected with a keyboard or gamepad.