- Home /
buttons to control ScrollView
Hi. Is it possible to add some buttons to the left and right side of a GUILayout.ScrollView that can beused for scrolling instead of using the slider?
so that it looks like this
left button| Scroll View| right button
<--|scroll view here|-->
Answer by sed · Oct 09, 2013 at 09:44 AM
If your ScrollView looks like this:
scrollPosition = GUILayout.BeginScrollView(scrollPosition,
GUILayout.Width(150), GUILayout.Height(150));
You can use:
if(GUILayout.Button(...))
{
scrollPosition.x = scrollPosition.x + 10; // vertical
scrollPosition.y = scrollPosition.y + 10; // horizontal
}
To scroll by pressing a button. To scroll the other way just swap + for -.
Won't work.
Assets/Scroll View/ScrollWindow.cs(22,25): error CS0019: Operator +=' cannot be applied to operands of type
UnityEngine.Vector2' and `int'
It's because scrollPosition is Vector2. Just fiddle with that and you will have your solution working. I have updated the answer to reflect that.
On a side note - you have to explore more on your own if you want to be a proficient programmer :)
Yeah. forgot to remove that comment. After a while I figured out how to fix it ;) Now there's only some problems with placing the buttons the right place, but that won't be too hard. Thanks for the help :)