I have scrolllist elements of which are several panels, with elements on them.

On one of these panels is an element that has a value, say, "active".

It is necessary for me that when immediately after loading the scene an automatic scrolling occurred to this element on one of the panels.

scheme .

    1 answer 1

    ScrollRect has a verticalNormalizedPosition property, which takes a value from 0 to 1. That is, from one extreme position to another. The quick version looks like this:

    • You need to remember the value of this verticalNormalizedPosition , when you screw it up to this element and it became active. If we make it active by default, then we have to calculate the scroll distance, for example, divide the unit by the number of elements.
    • Set a flag to track scrolling vertically LerpV . and based on it in Update scroll based on Mathf.Lerp and Mathf.Approximately . As an example:

      using UnityEngine; using System.Collections; using UnityEngine.UI; public class ScrollRectSnap : MonoBehaviour { ScrollRect scroll; bool LerpV; float targetV; void Start () { scroll = gameObject.GetComponent<ScrollRect>(); scroll.inertia = false; } void Update() { if(LerpV) { scroll.verticalNormalizedPosition = Mathf.Lerp( scroll.verticalNormalizedPosition, targetV, 10*scroll.elasticity*Time.deltaTime); if(Mathf.Approximately(scroll.verticalNormalizedPosition, targetV)) LerpV = false; } } } 

    where targetV is where you want to turn.