Scroll Rect, How to move an object without scroll wheel

Hi.

I’m having a major issue with the scroll rect. I seem able to get the scroll rect to scroll through its contents fine with the scroll wheel but when trying to use a button, it seems to keep snapping. Here’s the code so far in my Update loop.

if(Input.GetButtonUp("Return"))
{
           
    rect.verticalNormalizedPosition = rect.verticalNormalizedPosition + speed;
           
}

if(Input.GetAxis("Mouse ScrollWheel") != 0)
{
    Debug.Log(-Input.GetAxis("Mouse ScrollWheel"));

    rect.normalizedPosition = new Vector2(rect.normalizedPosition.x, rect.normalizedPosition.y + -Input.GetAxis("Mouse ScrollWheel"));
}

Any help about why this is not working it would be great. Speed is a global variable which I can amend at runtime and regardless of the value it doesn’t work…

Thanks

Hi,

Snapping…as in, it moves in too large steps, not smoothly?

No I mean that for a frame or so the content moves but is then instantly snapped back to the position before the scrolling was attempted.

Do you have a Scrollbar attached to the ScrollRect as well? If so, the ScrollRect position is being set to the Scrollbar’s value every frame. Try setting the Scrollbar value instead of directly accessing the ScrollRect position.

No I don’t though I suppose there’s no reason I couldn’t have one. It’s still confusing me while the scroll wheel is working though so I would like a solution to it without a scrollbar as well.

Just thought I’d mention, I think scrolling is working by default and my code is probably not actually affecting it. So if anybody else has methods for getting text to scroll using button inputs I’d be interested in seeing them.