Search code examples
c#unity-game-enginescrollbarscrollview

Scroll Rect manual scrolling through script Unity C#


I want to make a C# script for Unity to make the scroll view scroll up when I press "UP" key and scroll down when I press "DOWN" key.


Solution

  • Simply use

    ScrollRect.horizontalNormalizedPosition // value range (0 to 1)
    

    or

    ScrollRect.verticalNormalizedPosition // value range (0 to 1)
    

    try to lerp these values accordingly on button click event handlers for up and down buttons.

    Or you can have a look at scripts HorizontalScrollSnap.cs and VerticalScrollSnap.cs at UnityUI-Extentions