纳金网

标题: unity简单的单机登陆机制 [打印本页]

作者: may    时间: 2015-9-26 00:07
标题: unity简单的单机登陆机制

给游戏添加一个假的登陆机制
主要功能有:用户名和密码不能为空就可以登陆
直接上代码

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LoginGame : MonoBehaviour {
    public Text username;
    public Text password;
        // Use this for initialization
        void Start () {
        username = GameObject.Find("LoginGame/Panel/UserName/Text").GetComponent<Text>();
        password = GameObject.Find("LoginGame/Panel/PassWord/Text").GetComponent<Text>();
        print("username.text=" + username.text);
        }
    void Update()
    {
        print("ss" + username.text.IndexOf(" "));//检查是否有空格小于0 就有空格
    }
    public void LogainNewGame()
    {
        if ((username.text != string.Empty &&username.text.IndexOf(" ") < 0)&& password.text != string.Empty)
        {
            print("登陆成功");
        }
        else
        {
            print("登陆失败");
        }
    }
}






欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5