unity3d登录验证


最近的四个项目,统一加了一个登录界面,除了验证用户名和密码外,还加了一个到指定时间就不好用的功能,用这个来实现加密。
要点包括:GUIskin的设置,TextField,PasswordField,系统时间的获取等

using UnityEngine;
using System.Collections;

public class Login : MonoBehaviour {
public Texture bgTexture;
private float widthF = Screen.width;
private float heightF = Screen.height;
public GUIStyle dengluStyle;
public GUIStyle tuichuStyle;
private float btnWidth = 164;
private float btnHeight = 117;
public GUISkin windowSkin;
//帐号
private string _name;
//密码
private string _password;
public string nameInput=”";//获取输入的帐号
public string passwordInput = “”;//获取输入的密码

private bool tishi;
void Start(){
_name = “liaoshihua”;
_password = “liaoshihua”;
}
void OnGUI(){
GUI.DrawTexture(new Rect(0,0,widthF,heightF),bgTexture,ScaleMode.StretchToFill,true,10.0f);
GUI.skin = windowSkin;
nameInput = GUI.TextField(new Rect(690,392,150,30),nameInput);
passwordInput = GUI.PasswordField(new Rect(690,428,150,30),passwordInput,”*”[0],16);

if(GUI.Button(new Rect(550,440,btnWidth,btnHeight),”",dengluStyle)){

int yearStr = System.DateTime.Now.Year;
if(yearStr>2012){
return;
}
int monthStr = System.DateTime.Now.Month;
if(monthStr>10){
return;
}
int dayStr = System.DateTime.Now.Day;
if(dayStr>15){
return;
}

if(_name == nameInput && _password == passwordInput){
Application.LoadLevel(1);
tishi = false;
}else{
Debug.Log(“用户名或密码错误”);
tishi = true;
}

}
if(tishi){
GUI.Label(new Rect(850,392,150,30),”Try Again”);
}

if(GUI.Button(new Rect(710,440,btnWidth,btnHeight),”",tuichuStyle)){
Application.Quit();
}
}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值