AYE89

coding & learning

导航

unity3d之GUI

Posted on 2017-08-03 16:27  AYE89  阅读(174)  评论(0编辑  收藏  举报

1.Button

1  void OnGUI()
2     {
3         if (GUI.Button(new Rect(80, 80, 50, 20), "up"))
4         {flg=true; }
5         if (GUI.Button(new Rect(80, 120, 50, 20), "down"))
6         {flg=false; }
7         if (GUI.Button(new Rect(140, 100, 50, 20), "change"))
8         {flgChange=!flgChange; }
9     }

 

2.密码登陆

 1   void OnGUI()
 2     { 
 3         GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 50, 50, 20), "ACCOUNT");
 4         userName = GUI.TextField(new Rect(Screen.width / 2 - 40, Screen.height / 2 - 50, 100, 20), userName, 15);//15为最大字符串长度  
 5         //密码  
 6         GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 20, 50, 20), "PASSWORD");
 7         userPassword = GUI.PasswordField(new Rect(Screen.width / 2 - 40, Screen.height / 2 - 20, 100, 20), userPassword, '*');//'*'为密码遮罩  
 8         //信息  
 9         GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 + 30, 100, 20), info);
10         //登录按钮  
11         /* if (GUI.Button(new Rect(80, 80, 50, 20), "登录"))
12          {
13              if (userName == "zuoyamin" && userPassword == "123")
14              {
15                  info = "登录成功!";
16              }
17              else
18              {
19                  info = "登录失败!";
20              }
21          }*/
22 }