using System.Collections; using System.Collections.Generic; using UnityEngine; public class script1 : MonoBehaviour { private string userName;//帳號 private string userPassword;//密碼 private string info;//信息 void Start() { //初始化 userName = ""; userPassword = ""; info = ""; } void OnGUI() { //用戶名 GUI.Label(new Rect(20, 20, 50, 20), "帳號"); userName = GUI.TextField(new Rect(80, 20, 100, 20), userName, 15);//15為最大字串長度 //密碼 GUI.Label(new Rect(20, 50, 50, 20), "密碼"); userPassword = GUI.PasswordField(new Rect(80, 50, 100, 20), userPassword, '*');//'*'為密碼遮罩 GUI.Label(new Rect(220, 20, 100, 20), info); if (GUI.Button(new Rect(80, 80, 50, 20), "login")) { if (userName == "a" && userPassword == "1") { info = "登錄成功!"; } else { info = "登錄失敗!"; } } } }