Game Development Reference
In-Depth Information
For example, in order to create a verical scroll area at posiion x: 0, y: 0, width: 100 pixels,
and height: 40 pixels, which contains three butons with each buton having 40 pixels height,
we can have code like this:
var scrollPostion : Vector2 = Vector2.zero;
function OnGUI() {
scrollPostion = GUI.BeginScrollView(Rect(0,0,100,40), scrollPostion,
Rect(0,0,80,120));
GUI.Button(Rect(0,0,80,40),"Button 1");
GUI.Button(Rect(0,40,80,40),"Button 2");
GUI.Button(Rect(0,80,80,40),"Button 3");
GUI.EndScrollView();
}
From the preceding code, we can see that the GUI.BeginScrollView() funcion returns
Vector2 , which is a verical and horizontal of this scroll view. It also takes two Rect objects,
the first Rect is the area that the player will see or we can call a mask area. The second
Rect is the area of our content, which is based on the content that we included between
GUI.BeginScrollView() and GUI.EndScrollView() funcions, which are the three
lines of GUI.Button . We can also see more details of this funcion from the following URL.
http://unity3d.com/support/documentation/ScriptReference/GUI.
Be ginScrollView.html .
The following figure shows how the GUI.BeginScrollView() works in visual:
 
Search WWH ::




Custom Search