I am just leaning Unity, and upgrading an older database login script that used OnGUI before, to use the 4.6 Canvas elements instead.
I am looking to have the OnClick of the UI Button call the function void ClickLoginButton() in the custom script titled LoginMenu
the OnClick box in the inspector of the UI Button shows the name of my custom script, but doesn’t list any functions
(sorry just saw to use the developer preview forum for this)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
public class LoginMenu : MonoBehaviour {
private string loginURL = "http://xxx.xxx.xxx.xxx/login.php";
public static string username = "";
private string password = "";
private string label = "";
void ClickLoginButton(){
InputField username = GameObject.Find("usernameInput").GetComponent<InputField>();
string usernameSend = username.value;
InputField password = GameObject.Find("passwordInput").GetComponent<InputField>();
string passwordSend = password.value;
StartCoroutine(HandleLogin(usernameSend, passwordSend));
}
IEnumerator HandleLogin(string username, string password){
string loginURL = this.loginURL + "?username=" + username + "&password=" + password;
WWW loginReader = new WWW (loginURL);
yield return loginReader;
if(loginReader.error != null) {
label = "Error Connecting to Database Server.";
} else {
if(loginReader.text == "success"){
label = "Successfully logged in.";
Application.LoadLevel("Lobby");
} else {
label = "Invalid Username or Password.";
}
}
}
}