登录注册(本地存储)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class Zhuce : MonoBehaviour {
public GameObject One;
public GameObject Two;
public GameObject Three;
public InputField Use;//登录
public InputField Passward;//登录
public InputField Use_1;//注册
public InputField Passward_1;//注册
public Text text;//注册提示窗
public Text text1;//登录提示框
public string [] Name= new string [100];//存储用户,密码
public string [] Pass= new string [100];
public string [] Name1= new string [100];//读取用户,密码
public string [] Pass1= new string [100];
public int Key;
// Use this for initialization
void Start () {
Key = PlayerPrefs.GetInt("Key");
for (int i = 0; i < Key; i++)
{
Name[i] = "name" + i;
Pass[i] = "pass" + i;
Name1[i] = PlayerPrefs.GetString(Name[i]);
Pass1[i] = PlayerPrefs.GetString(Pass[i]);
}
}
// Update is called once per frame
void Update () {
}
//注册
public void RegisterOnClick()
{
if (Use_1.text!="" && Passward_1.text!="")
{
//print("6666666666");
bool IsExit = false;//假设Use_1.text != Name1[i]
for (int i = 0; i < Key; i++)
{
if (Use_1.text == Name1[i])
{
IsExit = true;
text.text = "该账号已存在!";
break;
}
}
if (IsExit==false)
{
//用户排序
Name[Key] = "name" + Key;
//存储用户信息
PlayerPrefs.SetString(Name[Key], Use_1.text);
//密码排序
Pass[Key] = "pass" + Key;
//存储密码信息
PlayerPrefs.SetString(Pass[Key], Passward_1.text);
Key++;
PlayerPrefs.SetInt("Key", Key);
for (int i = 0; i < Key; i++)
{
Name1[i] = PlayerPrefs.GetString(Name[i]);
Pass1[i] = PlayerPrefs.GetString ( Pass[i]);
}
text.text = "注册成功!";
}
}
else
{
text.text = "账号密码为空!";
}
}
//登录
public void LoginOnClick()
{
if (Use.text!="" && Passward.text!="")
{
for (int i = 0; i < Name1.Length; i++)
{
if (Use.text==Name1[i])
{
int a = Array.IndexOf(Name1, Name1[i]);
if (Passward.text==Pass1[a])
{
One.SetActive(false);
Two.SetActive(false);
Three.SetActive(true);
text1.text = "登陆成功!";
break;
}
else
{
text1.text = "密码错误!";
return;
}
}
else
{
text1.text = "账号不存在!";
}
}
}
else
{
text1.text = "账号密码为空!";
return;
}
}
public void Zhuce_1(string a)
{
if (a == "1")//One页 注册
{
One.SetActive (false);
Two.SetActive (true);
Three.SetActive (false);
}
//if (a == "2")//One页 登录
//{
// One.SetActive (false);
// Two.SetActive (false);
// Three.SetActive (true);
//}
if (a == "back")//Two页 返回
{
One.SetActive (true);
Two.SetActive (false);
Three.SetActive (false);
}
if (a == "3")//Three页 返回
{
One.SetActive (true);
Two.SetActive (false);
Three.SetActive (false);
}
}
}
浙公网安备 33010602011771号