Hello guys i need help about why my all gameobject deleted on next scene.
Scene 0 is a login and if login is done i go to scene 1 and all gameobjects on scene 1 “DELETED”
my connection script:
using UnityEngine;
using System.Collections;
public class Connection : MonoBehaviour
{
public string username = "";
public string password= "";
public string repassword= "";
public string email= "";
public string message= "";
public GUISkin hdskin;
public int HofBox = 25;
public int UserID;
public string loguser= "";
private string logpass= "";
private string logmessage= "";
private string mainDomainName= "http://avct.sytes.net/mmorpg";
private int generatednumber = 0;
private int numberinput;
public bool islogin = true;
private bool isregister = false;
public string CurrentMenu = "Menu";
//Chequea si tiene personaje
private int existCharacter;
public bool ExistChar = false;
void Start()
{
DontDestroyOnLoad (gameObject);
}
void OnGUI ()
{
if(CurrentMenu == "Menu")
{
GUI.skin = hdskin;
if(islogin == false && isregister == true)
{
GUI.Box( new Rect(Screen.width /2-250,20,500,480),"");
GUI.Label( new Rect(Screen.width /2-100,30,200,50),"Please fill out the fields");
GUI.Label( new Rect(Screen.width /2-230, 130,200,50),"Username:");
username = GUI.TextField( new Rect(Screen.width /2-20,130,200,HofBox),username,45);
GUI.Label( new Rect(Screen.width /2-230,190,200,50),"Password:");
password = GUI.PasswordField( new Rect(Screen.width /2-20,190,200,HofBox),password,"*"[0],45);
GUI.Label( new Rect(Screen.width /2-230,250,200,50),"Re-Enter pass:");
repassword = GUI.PasswordField( new Rect(Screen.width /2-20,250,200,HofBox),repassword,"*"[0],45);
GUI.Label( new Rect(Screen.width /2-230,310,200,50),"Email:");
email = GUI.TextField( new Rect(Screen.width /2-20,310,200,HofBox),email,45);
GUI.Label( new Rect(Screen.width /2-230,360,150,50),"Please verify:");
GUI.Label( new Rect(Screen.width /2-80,360,100,HofBox),generatednumber.ToString());
numberinput = int.Parse(GUI.TextField( new Rect(Screen.width /2+80,360,100,HofBox),numberinput.ToString()));
if(GUI.Button( new Rect(Screen.width /2-230,420,200,HofBox),"Register!"))
{
message = "";
if(username == "" || email == "" || password == "" || numberinput == 0){
message += "Please fill in the empty fields. \n";
}else{
if(password == repassword){
if(numberinput == generatednumber){
StartCoroutine("doRegister");
}else{
message += "The number you inputed is not the same number.";
}
}else{
message += "The passwords do not match. \n";
}
}
}
if(GUI.Button( new Rect(Screen.width /2-20,420,200,HofBox),"Return to login"))
{
islogin = true;
isregister = false;
username = ""; //cleaning our variables
password = "";
repassword = "";
email = "";
numberinput = 0;
message = "";
loguser = "";
logpass = "";
logmessage = "";
}
if(message != "")
{
GUI.Label( new Rect(Screen.width /2-230,460,460,50), message);
}}
else if(islogin == true && isregister == false)
{
StartCoroutine (ServerRefresh ());
GUI.Box( new Rect(Screen.width /2-250,20,500,450),"");
if(MasterServer.PollHostList().Length != 0)
{
HostData[] data = MasterServer.PollHostList();
foreach(HostData c in data)
{
GUILayout.BeginArea(new Rect(Screen.width /2-65,30,200,50));
GUILayout.Label(c.gameName + " " + (c.connectedPlayers - 1) + "/" + c.playerLimit);
GUILayout.EndArea();
}
}
else
{
GUILayout.BeginArea(new Rect(Screen.width /2-65,30,200,50));
GUILayout.Label("Server Offline");
GUILayout.EndArea();
}
GUI.Label( new Rect(Screen.width /2-230, 130,200,50),"Username:");
loguser = GUI.TextField( new Rect(Screen.width /2-20,130,200,HofBox),loguser,45);
GUI.Label( new Rect(Screen.width /2-230,230,200,50),"Password:");
logpass = GUI.PasswordField( new Rect(Screen.width /2-20,230,200,HofBox),logpass,"*"[0],45);
if(GUI.Button( new Rect(Screen.width /2-230,330,200,HofBox),"Login")){
if(loguser == "" || logpass == ""){
logmessage += "Please enter the necessary data! \n";
} else{
logmessage = "";
StartCoroutine("doLogin");
}
}
if(GUI.Button( new Rect(Screen.width /2-20,330,200,HofBox),"Register"))
{
islogin = false;
isregister = true;
generatednumber=Random.Range(1000,99999);
username = ""; //cleaning our variables
password = "";
repassword = "";
email = "";
numberinput = 0;
message = "";
loguser = "";
logpass = "";
logmessage = "";
}
if(logmessage != "")
{
GUI.Label( new Rect(Screen.width /2-230,360,460,50),logmessage);
}
}
}//CurrentMenu = Menu
if(CurrentMenu == "Logged")
{
islogin = true;
isregister = false;
StartCoroutine("CharacterCheck", 2.0F);
}//CurrentMenu = Logged
if (CurrentMenu == "Character")
{
if(ExistChar == true)//Si Tiene Personaje
{
Application.LoadLevel (1);
islogin = false;
}
if(ExistChar == false)//No Tiene Personaje
{
Application.LoadLevel (1);
islogin = false;
}
}//CurrentMenu = Character
}//OnGui
public void OnConnectedToServer()
{
CurrentMenu = "Logged";
}
private void OnDisconnectedFromServer()
{
CurrentMenu = "Menu";
}
private IEnumerator doRegister()
{
WWWForm form = new WWWForm();
form.AddField("Username" , username);
form.AddField("Password" , password);
form.AddField("Email" , email);
var w = new WWW(mainDomainName + "/Register.php", form);
yield return w;
if(w.error == null){
message += w.text;
StopCoroutine("doRegister");
}else{
message += "Error : " + w.error + "\n";
}
}
private IEnumerator doLogin()
{
WWWForm logform = new WWWForm();
logform.AddField("Username" , loguser);
logform.AddField("Password" , logpass);
var logw = new WWW(mainDomainName + "/Login.php", logform);
yield return logw;
if(logw.error == null){
logmessage += logw.text;
StopCoroutine("doLogin");
}else{
logmessage +="Error : " + logw.error + "\n";
}
if(logmessage == "Login success! Please wait while the game loads..."){
Network.Connect("avct.sytes.net", 8632);
}
}
private IEnumerator CharacterCheck()
{
WWWForm userInfoForm = new WWWForm();
userInfoForm.AddField("Username" , loguser);
var logw = new WWW(mainDomainName + "/CharacterCheck.php", userInfoForm);
yield return logw;
if(logw.error == null){
string[] data = logw.text.Split(new string[] {","}, System.StringSplitOptions.None);
UserID = System.Convert.ToInt32(data[0]);
existCharacter = System.Convert.ToInt32(data[1]);
yield return new WaitForSeconds(4);
if(existCharacter == 1)//Si Tiene Personaje
{
ExistChar = true;
CurrentMenu = "Character";
}
if(existCharacter == 0)//No Tiene Personaje
{
ExistChar = false;
CurrentMenu = "Character";
}
}else{
message +="Error : " + logw.error + "\n";
}
}
private IEnumerator ServerRefresh()
{
yield return new WaitForSeconds(3);
MasterServer.RequestHostList("MMOFPS");
}
}