Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Scrolling a ui list to find an item

Discussion in 'Getting Started' started by CyberInteractiveLLC, Dec 23, 2018.

  1. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    I 'am populating a transform ui scrollable list with ui elements prefabs, I'm trying to figure out a way to be able to specifiy a ui element after which the program will find that element, and scroll the list to have it on screen... not sure what to use to achieve this or if its possible??
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Of course it is. You'll use a for-loop to iterate through the items (probably using Transform.childCount and Transform.Child) until you find the one you want. Then you'll either calculate its position in the content container, or just look at its RectTransform properties to see what its position is, and set the scroll offset of your scroll view accordingly.
     
  3. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    ahh, I didn't think about getting transform positions of ui elements ... I will try