Scroll rect with mouse locked

Hello all

I have a scroll rect, that works ok if my mouse is unlocked, and i move the mouse over the the scoll rect. Happy days

However if my mouse is locked, which it will be as i dont plan on using the mouse, i can no longer scroll through my scroll rec.

basically when i toggle my scroll rec on my ui
i want to scroll with the up and down arrows.

Any ideas?

You’ll need to modify your scroll class or create a class to handle the scrolling and use it to handle input received and pass the scroll amount/direction to your scroll view object. Something like

public ScrollRect scrollRect;
public float speed;
public KeyCode Up, Down;
void Update()
{
    Vector2 velocity = Vector2.zero;
    if (Input.GetKey(Up))
    {
        velocity = Vector2.up * speed;
    }
    else if (Input.GetKey(Down))
    {
        velocity = -Vector2.up * speed;
    }
    scrollRect.velocity = velocity;
}