using UnityEngine;
using System.Collections;
public class Game_Menu_GUI : MonoBehaviour {
public string Username = "";
public string Password = "";
private string CreateUsername = "";
private string CreatePassword = "";
private string ConfirmPassword = "";
private string PlayerEmail = "";
public string CurrentGameMenu = "Login";
public string MenuText = "";
public string SecondMenuText = "";
void OnGUI () {
if(CurrentGameMenu == "Login"){
Login();
}else if (CurrentGameMenu == "CreateAccount") {
CreateAccount():
}
}
void Login () {
GUI.Label(new Rect(200, 250, 200, 25), "Enter your username:");
Username = GUI.TextField(new Rect(200, 275, 200, 25), Username);
GUI.Label(new Rect(200, 300, 200, 25), "Enter your password:");
Password = GUI.TextField(new Rect(200, 325, 200, 25), Password);
GUI.Label(new Rect(200, 350, 200, 25), MenuText);
if(GUI.Button(new Rect(200, 375, 200, 25), "Login")){
if(Username == "" || Password == ""){
MenuText == "Please fill in all info";
}else {
WWWForm form = new WWWForm();
form.AddField("Username", Username);
form.AddField("Password", Password);
WWW w = new WWW("http://???????????????.dx.am/login.php", form);
StartCorountine(LogIn(w));
}
}
if(GUI.Button(new Rect(200, 400, 200, 25), "Create an account")){
CurrentGameMenu = "CreateAccount";
}
}
void CreateAccount () {
GUI.Label(new Rect(200, 250, 200, 25), "Enter a username:");
CreateUsername = GUI.TextField(new Rect(200, 275, 200, 25), CreateUsername);
GUI.Label(new Rect(200, 300, 200, 25), "Enter a password:");
CreatePassword = GUI.TextField(new Rect(200, 325, 200, 25), CreatePassword);
GUI.Label(new Rect(200, 350, 200, 25), "Confirm password:");
ConfirmPassword = GUI.TextField(new Rect(200, 375, 200, 25), ConfirmPassword);
GUI.Label(new Rect(200, 400, 200, 25), "Enter your email:");
PlayerEmail = GUI.TextField(new Rect(200, 425, 200, 25), PlayerEmail);
GUI.Label(new Rect(200, 450, 200, 25), SecondMenuText);
if(GUI.Button(new Rect(200, 475, 200, 25), "Create Account")){
if(CreateUsername != "" || PlayerEmail != ""){
if(CreatePassword == ConfrirmPassword){
WWWForm form = new WWWForm();
form.AddField("CreateUsername", CreateUsername);
form.AddField("ConfirmPassword", ConfirmPassword);
WWW w = new WWW("http://???????????.dx.am/register.php", form);
StartCorountine(CreateAccount(w));
}
}
}
if(GUI.Button(new Rect(200, 500, 200, 25), "Cancel Account Creation")){
CurrentGameMenu = "Login";
}
}
private IEnumerator Login(WWW _w) {
yield return _w;
if(_w.error == null){
if(_w.text == "Log in successful!"){
//What happens to the player when he logs in:
}else {
MenuText = _w.text;
}
}else {
MenuText = "Error" + _w.error;
}
}
private IEnumerator CreateAccount(WWW _w) {
yield return _w;
if(_w.error == null) {
SecondMenuText = _w.text;
}else {
SecondMenuText = "Error" + _w.error;
}
}
}
I have taken the code you gave me and changed a few things for my game’s purpose. Will something like this code work?