unity3d下拉菜单

来源:互联网 发布:佛山广电网络营业厅 编辑:程序博客网 时间:2024/05/18 03:24
// unity3d下拉菜单效果
//you can use or mod this file anyway you like and if you make something cool out of it


// and like to share it send it to piershaw@gmail.com


//just add it to a cam or empty gameObject
// to add buttons just Repeat what you see


private var Ypos1 : float = 0.0;


private var Ypos2 : float = 0.0;


private var Ypos3 : float = 0.0;


private var Ypos4 : float = 0.0;
private var showDropdownButtons1 : boolean;


private var showDropButtonsUP1 : boolean;
var dropSpeed : float = 400.0;// if you like change the speed
function Update(){
if(showDropdownButtons1 == true){
Ypos1 += Time.deltaTime * dropSpeed;


Ypos2 += Time.deltaTime * dropSpeed;


Ypos3 += Time.deltaTime * dropSpeed;


Ypos4 += Time.deltaTime * dropSpeed;
if(Ypos1 >= 30){


Ypos1 = 30;


}
if(Ypos2 >= 60){


Ypos2 = 60;


}
if(Ypos3 >= 90){


Ypos3 = 90;


}
if(Ypos4 >= 120){


Ypos4 = 120;


}
if(showDropButtonsUP1 == true){


Ypos1 -= Time.deltaTime * dropSpeed;


Ypos2 -= Time.deltaTime * dropSpeed;


Ypos3 -= Time.deltaTime * dropSpeed;


Ypos4 -= Time.deltaTime * dropSpeed;
if(Ypos1 >= 0 || Ypos2 >= 0 || Ypos3 >= 0 || Ypos4 >= 0){


Ypos1 = 0;


Ypos2 = 0;


Ypos3 = 0;


Ypos4 = 0;


showDropButtonsUP1 = false;


showDropdownButtons1 = false;


}


}
}
}
// you can change anything in red


function OnGUI (){
if(showDropdownButtons1 == false){


if (GUI.RepeatButton (Rect (50, 0, 100, 30), "Select")){


showDropdownButtons1 = true;


}


}
if(showDropdownButtons1 == true){
if (GUI.Button (Rect (50, 0, 100, 30), "Select")){


showDropButtonsUP1 = true;


showDropdownButtons1 = false;


}
if (GUI.Button (Rect (50, Ypos1, 100, 30), "1")){


showDropButtonsUP1 = true;


showDropdownButtons1 = false;


}
if (GUI.Button (Rect (50, Ypos2, 100, 30), "2")){


showDropButtonsUP1 = true;


showDropdownButtons1 = false;


}
if (GUI.Button (Rect (50, Ypos3, 100, 30), "3")){


showDropButtonsUP1 = true;


showDropdownButtons1 = false;


}
if (GUI.Button (Rect (50, Ypos4, 100, 30), "4")){


showDropButtonsUP1 = true;


showDropdownButtons1 = false;


}
}
}