脚本内容为
登陆成功将会打出success!
以及
多行输出的 静夜思
账号 wonameshuai
密码nishuodedui
using UnityEngine;
using System.Collections;
public class Label : MonoBehaviour {
private string userName;
private string passWord;
private string username;
private string password;
private string message;
private string info;
public Texture img;
void OnGUI()
{
GUIStyle sty = new GUIStyle();
GUIStyle sty1 = new GUIStyle();
sty.fontSize = 20;
sty1.fontSize = 40;
GUI.Label(new Rect(120, 10, 100, 30), "登录界面", sty1);
GUI.Label(new Rect(30, 70, 100, 30),"用户名:",sty);
userName = GUI.TextField(new Rect(120, 70, 200, 30),userName,20);
GUI.Label(new Rect(30, 110, 100, 30), "密码:",sty);
passWord = GUI.PasswordField(new Rect(120, 110, 200, 30), passWord, '*', 15);
message = GUI.TextArea(new Rect(400, 30, 200, 200), message, sty);
if (GUI.Button(new Rect(220, 150, 110, 30), "login"))
{
if (username == userName && password == passWord)
{
info = "success!";
message = "床前明月光,\n疑是地上霜。\n举头望明月,\n低头思故乡。\n";
}
else
info = "failed!";
}
sty.fontSize = 40;
GUI.Label(new Rect(150, 210, 512, 225), info,sty);
}
// Use this for initialization
void Start () {
userName = "";
passWord = "";
message = "";
info = "";
username = "wonameshuai";
password = "nishuodedui";
}
// Update is called once per frame
void Update () {
}
}
这里写图片描述
由于在课堂上写的并没有做太多的UI美化
大概看着顺眼就行了
但是
重点内容
从账户密码是代码里面定死的
并没有从任何地方获取
网友评论