Search Unity

Scroll Rect auto scroll over time?

Discussion in 'UGUI & TextMesh Pro' started by Twanner, Feb 15, 2019.

  1. Twanner

    Twanner

    Joined:
    Dec 6, 2014
    Posts:
    33
    Hey everyone, I'm trying to figure out how to access the "value" float on a slider for a scroll rect so that I can write up a quick script to make it auto-scroll. Anyone know how I can do that?
     
  2. Twanner

    Twanner

    Joined:
    Dec 6, 2014
    Posts:
    33
    Since I haven't seen a response, Does anyone have any idea how to auto scroll via some other method? I'm open to suggestions.
     
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @Twanner

    I have no idea what is the correct way to do this, but ScrollRect content is just a regular RectTransform.

    I don't think you have to involve slider into this.

    You could use: scrollRect.content.localPosition. If you have setup ScrollRect Movement Type to Clamped, this movement will still be clamped. So for example, some sin movement in y-axis will be clamped to panel ends even if it's values would move it past allowed limits:
    Code (CSharp):
    1. var pos = new Vector2(0f, Mathf.Sin(Time.time * 10f) * 100f);
    2. scrollRect.content.localPosition = pos;
    If you want to move content using 0-1 normalized position values, then there is ScrollRect.normalizedPosition, this will move the content directly between it's end points AFAIK.
     
    yym28088, LGames_ and Twanner like this.
  4. Twanner

    Twanner

    Joined:
    Dec 6, 2014
    Posts:
    33
    Thanks eses! That works perfectly!