- 最后登录
- 2014-5-7
- 注册时间
- 2013-7-12
- 阅读权限
- 90
- 积分
- 11615
- 纳金币
- 454
- 精华
- 31
|
这段脚本主要实现一个group的伸缩功能,group里面的内容也就是菜单的内容可以自由添加。
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);
}
}
|
|