这段脚本主要实现一个group的伸缩功能,group里面的内容也就是菜单的内容可以*添加。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
var LeftGroupToTop:int=60;
var LeftGroupWidth:int=300;
var LeftGroupHeight:int=700;
var LeftGroupLabelWidth:int=30;
private var MoveDistance =LeftGroupLabelWidth-LeftGroupWidth;
private var XPosition;
private var StartPoint:float=MoveDistance;
function Update(){
//获取鼠标的x坐标位置
XPosition=Input.mousePosition.x;
if (XPosition<LeftGroupLabelWidth){
OpenLeftGroup ();
}
if (XPosition>LeftGroupWidth){
CloseLeftGroup();
}
} function OnGUI () {
GUI.Box(Rect(100,0,100,400),XPosition.ToString()); //可以去掉,调试看效果用的
GUI.Box(Rect(100,500,100,400),StartPoint.ToString()); //可以去掉,调试看效果用的
//下面是组里面的内容
GUI.BeginGroup(Rect(StartPoint,LeftGroupToTop,LeftGroupWidth,LeftGroupHeight));
GUI.Box(Rect(0,0,LeftGroupWidth,LeftGroupHeight), "" );
GUI.Box(Rect(LeftGroupWidth- LeftGroupLabelWidth,0,LeftGroupLabelWidth,LeftGroupHeight), "qiyechaxun" );
GUI.EndGroup (); //组结束
} //控制菜单的伸出 function OpenLeftGroup () {
if (StartPoint < 0.0) {
StartPoint +=1.0;
yield WaitForSeconds (2);
}
} //控制菜单的收回 function CloseLeftGroup () {
if (StartPoint >MoveDistance) {
StartPoint -=0.1;
yield WaitForSeconds (5);
}
} |