Search code examples
unity-game-enginescrollview

How to focus last object in scrollview in unity


I have a scrollView, where the clones of prefabs will generate horizontally. Here I wanted to focus last generated clone. How to achieve that?


Solution

  • You can set the position of the scroll rect. IN your case I'd guess you want to set it to 1:

    myScrollRect.horizontalNormalizedPosition = 1f;
    

    https://docs.unity3d.com/ScriptReference/UI.ScrollRect-horizontalNormalizedPosition.html