Game Development Reference
In-Depth Information
Classified intel
We have created a vertical and horizontal scroll view by using
GUI.BeginScrollView()
to begin the scroll view and ended it with
GUI.EndScrollView()
. Basically, we can use this function, which is very convenient
to use, when we want to create a scrollable area that contains any type of a
GUI
object, be-
cause this function will automatically create a scrollable area from the two
Rect
paramet-
ers that we set up.
For example, in order to create a vertical scroll area at position
x
:
0
,
y
:
0
,
Width
:
100
pixels, and
Height
:
40
pixels, which contains three buttons with each button having 40
pixels height, we'd use code similar to the following snippets:
// Unity JavaScript user:
var scrollPostion : Vector2 = Vector2.zero;
function OnGUI() {
scrollPostion = GUI.BeginScrollView(new Rect(0,0,100,40),
scrollPostion, new Rect(0,0,80,120));
GUI.Button(new Rect(0,0,80,40),"Button 1");
GUI.Button(new Rect(0,40,80,40),"Button 2");
GUI.Button(new Rect(0,80,80,40),"Button 3");
GUI.EndScrollView();
}
// C# user:
Vector2 scrollPostion = Vector2.zero;
void OnGUI() {
scrollPostion = GUI.BeginScrollView(new
Rect(0,0,100,40),scrollPostion, new Rect(0,0,80,120));
GUI.Button(new Rect(0,0,80,40),"Button 1");
GUI.Button(new Rect(0,40,80,40),"Button 2");
GUI.Button(new Rect(0,80,80,40),"Button 3");
GUI.EndScrollView();
}