纳金网

标题: unity3d下拉菜单实现代码 [打印本页]

作者: 她。    时间: 2012-7-27 16:55
标题: unity3d下拉菜单实现代码
// 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 == ***e){
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 == ***e){

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 = ***e;

}

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

showDropButtonsUP1 = ***e;

showDropdownButtons1 = false;

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

showDropButtonsUP1 = ***e;

showDropdownButtons1 = false;

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

showDropButtonsUP1 = ***e;

showDropdownButtons1 = false;

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

showDropButtonsUP1 = ***e;

showDropdownButtons1 = false;

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

showDropButtonsUP1 = ***e;

showDropdownButtons1 = false;

}
}
}
作者: osaka    时间: 2012-7-27 21:48
不错!!!!!!!!!!!!
作者: 她。    时间: 2012-8-3 18:02
我爱纳金网~www.narkii.com
作者: Zack    时间: 2012-11-25 03:51
学习了。谢谢!
作者: 王者再临    时间: 2012-11-25 11:45
那些 *** 是啥代码啊。。




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5