I’m not totally sure how the scrollView works exactly. When I tried implementing it, the buttons appear and all that good stuff, but the scrollbar doesnt move, and basically it doesn’t scroll.
scrollPosition = GUI.BeginScrollView(new Rect(0,50,width/2,height), scrollPosition,
new Rect(0,0,width/2,height*2));
float px = 0;
float py = 0;
float tw = 50;
float th = 50;
for(int i = 0; i < 10; i++) {
GUI.Button(new Rect(px,py,tw,th), "button: " + i);
py += 75;
}
GUI.EndScrollView();
}
Try this:
Vector2 scrollPosition = Vector2.zero;
float height = Screen.height;
float width= Screen.width;
void OnGUI(){
scrollPosition = GUI.BeginScrollView(new Rect(0,50,width/2,height), scrollPosition,
new Rect(0,0,width/2,height*2));
float px = 0;
float py = 0;
float tw = 50;
float th = 50;
for(int i = 0; i < 10; i++) {
GUI.Button(new Rect(px,py,tw,th), "button: " + i);
py += 75;
}
GUI.EndScrollView();
}
Where do you declare scrollPosition. If you declare it inside OnGUI() it won’t work because it’s reseting the scrollposition each Game Tick. You have to declare scrollposition outside of a function like this:
var scrollPosition : Vector2;
Hope this works for you.