- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38266
- 精华
- 111
|
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;
-
- }
-
- }
-
- }
复制代码 |
|