嗨,这是我的代码。
Unity通过PHP代码连接mysql。
public string userLoginFile = "localhost:8088/database/Userlogin.php?";
string username = "****";
string password = "****";
string Name;
bool InfoTest = false;
string family;
string status;
Text we;
Text st;
public void Start(){
GameObject inputUsernameFiled = GameObject.Find ("usernameInput");
GameObject inputPasswordFiled = GameObject.Find ("passwordInput");
GameObject welcomeQ = GameObject.Find ("welcome");
GameObject statusQ = GameObject.Find ("status");
we = welcomeQ.GetComponent<Text> ();
st = statusQ.GetComponent<Text> ();
InputField In1 = inputUsernameFiled.GetComponent<InputField> ();
InputField In2 = inputPasswordFiled.GetComponent<InputField> ();
//st.text = "Your Account Is Saved!";
if(PlayerPrefs.GetFloat ("InfoCheck") == 1){
username = In1.text;
password = In2.text;
we.text = "Welcome To Golden3 Service!";
//st.text = "Your Status Is: " + status;
}
if(PlayerPrefs.GetFloat ("InfoCheck") == 2){
username = PlayerPrefs.GetString ("UsernameIs");
password = PlayerPrefs.GetString ("PasswordIs");
StartCoroutine (LoginUser (username, password));
st.text = "Your Account Is Connect!";
we.text = "Welcome "+ Name +" To Golden3 Service!";
Debug.Log (Name);
}
}
void Update(){
//Awake ();
}
public void OnClick(){
if(PlayerPrefs.GetFloat ("InfoCheck") == 1){
PlayerPrefs.SetString ("UsernameIs", username);
PlayerPrefs.SetString ("PasswordIs", password);
PlayerPrefs.SetFloat ("InfoCheck", 2);
StartCoroutine (LoginUser (username, password));
if(InfoTest == true){
st.text = "Your Status Is: Connectet";
Debug.Log (Name);
}//end if
}//end if
}// end click function
IEnumerator LoginUser(string user, string pass){
WWW login = new WWW(userLoginFile + "username=" + user + "&password=" + pass);
yield return login;
if(login.error == null){
InfoTest = true;
Name = "test";
/*
string[] credentials = login.text.Split('/');
foreach (string str in credentials){
string[] cred= str.Split('=');
for(int i =0; i< cred.Length; i++) {
if(cred[i] == "name")
Name = cred[i+1];
if(cred[i] == "family")
family = cred[i+1];
status = "Logged In!";
}
}*/
}//end if
}//end login user
在启动函数调用startcoroutine时,不起作用
但是当我点击按钮时,startcoroutine Works!
请帮助我!
感谢。
答案 0 :(得分:0)
if(PlayerPrefs.HasKey("UsernameIs")){ username = PlayerPrefs.GetString ("UsernameIs"); }else{ username="****"; } if(PlayerPrefs.HasKey("PasswordIs")){ password = PlayerPrefs.GetString ("PasswordIs"); }else{ password ="****"; }