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

Scrolling Inventory - Question about scroll rects and UI

Discussion in 'UGUI & TextMesh Pro' started by Kettlewell, Aug 11, 2015.

  1. Kettlewell

    Kettlewell

    Joined:
    Jun 24, 2015
    Posts:
    19
    Hello everyone, I have a bit of problem attempting to figure out the best method to perform what I'm after and I hope someone may be able to help.

    I have a panel in my game which I need to add inventory items into (Check picture) so that the player may be able to scroll up and down to select which item they want now my problem is how to do this.

    I've thought about using a scroll rect with a image/mask then every time I add an item I will increase the content of the scroll rects height variable (Which is a panel) and place a new UI prefab onto that panel meaning the panel is only ever as big as the content.

    Is this the right method? 2 panels, one with with a scroll rect/mask/image and other just actively updating its size as i add prefabs.

     
  2. Mikea15

    Mikea15

    Joined:
    Sep 20, 2012
    Posts:
    93
    In order to make the scrollrect work you have to have a content inside that is bigger than the content rect.
    What I usually do is something like this:
    Code (CSharp):
    1. - scrollrect ( scrollrect + mask )
    2.   - content ( vertical layout group. uncheck width/height + content size fitter -> set the axis you want to expand to prefered size. )
    3.      - child 1 ( layout element with height/width )
    4.      - ...
    5.      - child n
    Check the images ;)
    Hope that helps.
     

    Attached Files:

    Kettlewell likes this.
  3. Kettlewell

    Kettlewell

    Joined:
    Jun 24, 2015
    Posts:
    19
    I love you, I never knew about groups before