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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Auto scroll content with selected item

Discussion in 'Scripting' started by clebertavares, Nov 29, 2019.

  1. clebertavares

    clebertavares

    Joined:
    Jan 2, 2012
    Posts:
    55
    Hello,

    I have a dropdown menu, working fine:



    Using mouse/touch. But, I would like to use now the keyboard/joystick with buttons to control it.

    I can select the dropdown items and navigate, you can notice the fourth item is selected ("Atlantis"... in red).

    But, if I go down to the next item bellow it... using only keyboard for example... the content dont scrolldown automatically...

    How can I do that?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    set slider position manually to item position y / scroll bounds height
     
  3. clebertavares

    clebertavares

    Joined:
    Jan 2, 2012
    Posts:
    55
    Where do I have the info of which item is selected?
     
  4. clebertavares

    clebertavares

    Joined:
    Jan 2, 2012
    Posts:
    55
    Well, I solve this way


    if (Input.blablablagetbuttondown)
    {
    TemplateViewPortContentRectTransform.anchoredPosition += new Vector2(0,
    TemplateViewPortContentItemRectTransform.sizeDelta.y);
    }


    With some name changes to explain better what are the objetcs... And equivalent code to go up.