Search Unity

Cause a ScrollRect to scroll with code

Discussion in 'UGUI & TextMesh Pro' started by Tomer-Barkan, Nov 13, 2014.

  1. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    Hi,

    I'm trying to do something fairly simple with ScrollRect and VerticalLayoutGroup - a log system.
    The idea is that logs are added to the layout group (simple Text gameobjects), and once the display area is full, any new log will scroll down so that the latest log is visible.

    I tried a few things, but none seem to work. Any help will be appreciated:

    1. I tried setting the "velocity" property of the scrollrect to positive Y every time a new message is added, so that it will scroll up. This half worked. At first, it would not move the scroll at all. If at some point I drag the scroll myself using the mouse, then from this point forwards the scroll will indeed move automatically, but until I drag it manually the velocity has no effect.

    2. I tried manually moving the transform position of the contents upwards with every new log. In elastic this caused the content to move up then bounce back down every time. In clamped, the content would move outside of the mask and remain there.

    Any ideas? #1 seems a bit like a possible bug to me, and maybe #2 with clamped as well.

    Thanks
     
  2. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
  3. RakshithAnand

    RakshithAnand

    Joined:
    Jun 30, 2013
    Posts:
    56
    Well, have you tried using verticalNormalizedPosition?
    Everytime you add a new log you could set verticalNormalizedPosition to 1 ..
    This is considering you want to move up. Else set it to 0 to move to the bottom.

    Maybe to get the scroll effect you could try to ease in the verticalNormalized position with an ease in function from current to 1(for moving to top else 0) so that it would give that scroll up/down effect
     
    Last edited: Nov 18, 2014
    JoeStrout likes this.