What's the difference between ScrollView and VerticalScroll?

Hi,

I’ve been trying to use GUI.Verticalscrollbar but couldn’t get it to work properly. I do have the scrollbar on the screen but I don’t know how to see the scroll area? So then I read about ScrollView and the tried example from the documentation

var scrollPosition = Vector2.zero

function OnGUI()
{
 scrollPosition = GUI.BeginScrollView(Rect(x,y, width,height), scrollPosition, Rect(0,0, 200, 800));

//stuffhere

GUI.ScrollView();
}

In addition to my VerticalScrollbar, I now have 2 additional bars both horizontal and vertical. How do I just use the VerticalScrollBar? Can I just use it instead of ScrollView or do they have to be combined together?

Thanks in advance.
-Hakimo

A Scrollbar is just the bar itself without any associated scrollable area. A ScrollView is a scrollable area that displays scrollbars when necessary. To stop the horizontal scrollbar being displayed, just make sure that the width of the view rectangle you pass to BeginScrollView is less than the width of the scrollview.

Hi Andeeee,

I have removed the horizontal area and it works fine I think. Right now, I’m checking to see if I can change the skin for the scrollbar and thumb.

If the scrollbar is not associated with a scrollable area, what is it for actually?

Thanks.
-Hakimo

It’s for any time you need a scrollbar-like widget to implement some GUI functionality like, of, a scrollable area, for example :wink: Scrolling is usually done with a ScrollView since that generally covers the majority of situations where you’d need a scrollbar, but the stand-alone widget is there if you should need it for something else.

Hi Laurie,

Thanks again for the reply. One more question: For the stand alone widget, what kind of “something else” can I use it for? The documentation doesn’t say anything about a “beginArea” to use it with :stuck_out_tongue:

Also, can I actually use the scroll slider widget with the scrollview? Because I can’t set the values in the scrollbar in the scrollview. Basically I’d like to use the virtual slider to scroll images vertically like a gallery but not sure how to approach it.

Thanks again.
-Hakimo

the something else is pretty simple: Any bar widget like volume bar, detail level bar, terrain detail distance, shadow distance, mouse sensivity even color if it comes from a restricted list of selections for example could be done that way

Yep, any situation where you want to be able to select a value from a continuous range. If you use a horizontal/vertical widget directly, you don’t get ‘something to use it with’ – you’re using it directly, and can pair it with whatever you want.

You also don’t need to use a scrollbar widget with a scrollview; the whole point of the scrollview is that it handles the scrollbars for you.

For your gallery example, you would just call Gui.BeginScrollView() with a view rect that’s as wide as (or wider than) than your images, and tall enough for all of them to fit; then use GUI.DrawTexture() for each of the images and, finally, call GUI.EndScrollView().

Or use GUILayout so you don’t have to handle the calculation manually and keep the code shorter and more readable