ScrollView - How to stop infinite scrolling?

So I’m having the Unrestricted MoveType Scrollview (Only Vertical), Inside I’m having the VerticalLayoutGroup filled with buttons. But the problem is that user can scroll into infinity. I want to stop scrolling when the last button is at the bottom of the view. How do I achieve that?

How to stop infinite scrolling in scrollview ?

It’s a little hard, not impossible, what we are going to do, is set the maximum value to the amount of buttons like this…

int buttonSize = 80;
int numberOfButtons = 4;
int mValue = buttonSize*numberOfButtons;

In a scrollview, the content need to put in this GameObject → ScrollView>Viewport>Content.
The content recttransform is changed when you scroll stuff. We can’t let it’s TOP value be higher than 0, so we do this:

public RectTransform cont;

void Update(){
	if(cont.offsetMax.y < 0) { //It seems that is checking for less than 0, but the syntax is weird
		cont.offsetMax = new Vector2(); //Sets its value back.
		cont.offsetMin = new Vector2(); //Sets its value back.

Now we can’t let the value be higher than the number of buttons, so we do this:

if(cont.offsetMax.y>(numberOfButtons*buttonSize)-buttonSize) { // Checks the values
	cont.offsetMax = new Vector2(0,(numberOfButtons*buttonSize)-buttonSize); // Set its value back
	cont.offsetMin = new Vector2(); //Depending on what values you set on your scrollview, you 			 								might want to change this, but my one didn't need it.

Hope this helps :slight_smile: