靠边伸缩菜单的做法(类似QQ,碰到就会伸出来)

这段脚本主要实现一个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);
      } 
}
posted @ 2010-09-17 08:48  子非あ鱼  阅读(1841)  评论(5编辑  收藏  举报