Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

ScrollViewScope

class in UnityEngine

Switch to Manual

Description

Disposable helper class for managing BeginScrollView / EndScrollView.

Automatically laid out scrollviews will take whatever content you have inside them and display normally. If it doesn't fit, scrollbars will appear. A call to BeginScrollView must always be matched with a call to EndScrollView.


Scroll View in the Game View..

#pragma strict
public var scrollPosition: Vector2;
public var longString: String = "This is a long-ish string";
function OnGUI() {
	var scrollViewScope: var = new ScrollViewScope(scrollPosition, GUILayout.Width(100), GUILayout.Height(100));
	{
		scrollPosition = scrollViewScope.scrollPosition;
		// scrollbars will work correctly with wordwrap.
		GUILayout.Label(longString);
		// for the vertical scrollbar
		if (GUILayout.Button("Clear"))
			longString = "";
	}
	// the scrolling area.
	if (GUILayout.Button("Add More Text"))
		longString += "\nHere is another line";
}

Variables

handleScrollWheelWhether this ScrollView should handle scroll wheel events. (default: true).
scrollPositionThe modified scrollPosition. Feed this back into the variable you pass in, as shown in the example.

Constructors

GUILayout.ScrollViewScopeCreate a new ScrollViewScope and begin the corresponding ScrollView.