unityGUI下拉菜单实现代码

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;
}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值