Hi all, I am having trouble writing a script to scroll a ScrollRect at a constant speed, regardless of the size of the content.
I have a ScrollRect with a mask, with a text layer using the contentfitter component.
I have a scroll bar (which is invisible) and I set the value through code to scroll a dialog window. Simple stuff…
But of course, seeing as the min and max value is 0 - 1, that means that when there is little text, it scrolls slowly, and when there is loads it scrolls super fast.
Thats because I was using:
if (_player.GetAxis("WheelScroll") > 0)
{
scroller.value += scrollSpeedMouse;
}
Clearly that wont work.
So I figured that I needed to find some way to scale the speed, based on the height of the content maybe…
So I tried the following:
public float textHeight;
public Text dialogText;
float textHeight;
textHeight = dialogText.preferredHeight;
if (_player.GetAxis("WheelScroll") > 0)
{
scroller.value += scrollSpeedMouse * textHeight;
}
I thought that this might work, but alas it still doesnt scale well.
I’m probably being dumb here, but there must be a way to scroll at a constant speed regardless of the content size…
Any ideas?