GUI.ScrollTo 滚动至

static function ScrollTo (position : Rect) : void

Description描述

Scrolls all enclosing scrollviews so they try to make position visible.

滚动scrollviews到position指定的位置,通俗来说就是把内容滚动到指定的坐标。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Vector2 scrollPos = Vector2.zero;
	void OnGUI() {
		scrollPos = GUI.BeginScrollView(new Rect(10, 10, 100, 50), scrollPos, new Rect(0, 0, 220, 10));
		if (GUI.Button(new Rect(0, 0, 100, 20), "Go Right"))
			GUI.ScrollTo(new Rect(120, 0, 100, 20));

		if (GUI.Button(new Rect(120, 0, 100, 20), "Go Left"))
			GUI.ScrollTo(new Rect(0, 0, 100, 20));

		GUI.EndScrollView ();
	}
}
var scrollPos : Vector2 = Vector2.zero;

function OnGUI () {
	scrollPos = GUI.BeginScrollView(Rect (10, 10, 100, 50), scrollPos, Rect(0, 0, 220, 10));
	//绘制一个滚动视窗
	if(GUI.Button(Rect (0,0,100,20), "Go Right"))
	//左边创建一个按钮,点击将滚动到右边
		GUI.ScrollTo(Rect (120,0,100,20));
	
	if(GUI.Button(Rect (120,0,100,20) , "Go Left"))
	//右边创建一个按钮,点击将滚动到左边
		GUI.ScrollTo(Rect (0,0,100,20));

	// 结束滚动视图
	GUI.EndScrollView ();
}
Page last updated: 2011-1-14