Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

nabilfx

script Login

Recommended Posts

tenho este script para login e register, no android funciona, mais no iphone os botões funcionan mais o script não funciona, o que poderia ser?

aqui o script.

using UnityEngine;
using System.Collections;
 
public class LoginSystem : MonoBehaviour {
 
    public enum lMode{login,register};
    public lMode LoginMode;
 
    public GUISkin skin;
    //login
    private string user = "";
    private string pass = "";
    private bool   remember;
    private int    boolstatus;
    //register
    private string name = "";
    private string password = "";
    private string email = "";
 
    public string Log;
    public Texture LogTexture;
 
    public string sceneMap;
 
    void Start () {
        boolstatus = PlayerPrefs.GetInt("bs");
        if (boolstatus == 1) {
            remember = true;
        }else{
            remember = false;
        }
        if (remember == true) user = PlayerPrefs.GetString ("login");
    }
 
    void Update () {
        if (remember == true) {
            PlayerPrefs.SetString("login",user);
            boolstatus = 1;
            PlayerPrefs.SetInt("bs",boolstatus);
        }else{
            boolstatus = 0;
            PlayerPrefs.SetInt("bs",boolstatus);
        }
    }
    void OnGUI(){
        GUI.skin = skin;
 
        GUI.DrawTexture (new Rect (Screen.width / 2 -288, Screen.height / 2 -200, 576, 500), LogTexture);
 
        GUILayout.BeginArea(new Rect(Screen.width/2 -180,Screen.height/2 +178,380,40),"","");
        GUILayout.Label ("<color=black>"+Log+"</color>");
        GUILayout.EndArea();
 
        if (LoginMode == lMode.login) {
            GUILayout.BeginArea(new Rect(Screen.width/2 -190,Screen.height/2 -135,380,270),"","Box");
            LoginGUI();
            GUILayout.EndArea();
        }else if (LoginMode == lMode.register){
            GUILayout.BeginArea(new Rect(Screen.width/2 -190,Screen.height/2 -135,380,300),"","Box");
            RegisterGUI();
            GUILayout.EndArea();
        }
    }
    void LoginGUI(){
        GUILayout.BeginHorizontal ("",skin.customStyles[1]);
        GUILayout.Label ("<size=21>Usuário</size>");
        user = GUILayout.TextField (user,15,GUILayout.Width(280),GUILayout.Height(40));
        GUILayout.EndHorizontal ();
        GUILayout.Space (4);
        GUILayout.BeginHorizontal ("",skin.customStyles[1]);
        GUILayout.Label ("Senha");
        pass = GUILayout.PasswordField(pass,"*"[0],20,GUILayout.Width(280),GUILayout.Height(40));
        GUILayout.EndHorizontal ();
        GUILayout.BeginHorizontal ();
        GUILayout.FlexibleSpace ();
        GUILayout.Label ("<size=21>Lembrar Usuário</size>",GUILayout.Width(180));
        remember = GUILayout.Toggle (remember,"", GUILayout.Width (40), GUILayout.Height (40));
        GUILayout.EndHorizontal ();
        GUILayout.FlexibleSpace ();
        if(GUILayout.Button("Logar-se",GUILayout.Height(50))){
            Log = "";
            RequestLogin();
        }
        if(GUILayout.Button("Registrar-se",GUILayout.Height(50))){
            Log = "";
            LoginMode = lMode.register;
        }
    }
    void RegisterGUI(){
        GUILayout.BeginHorizontal ("",skin.customStyles[1]);
        GUILayout.Label ("<size=21>Usuário</size>");
        name = GUILayout.TextField (name,15,GUILayout.Width(280),GUILayout.Height(40));
        GUILayout.EndHorizontal ();
        GUILayout.Space (4);
        GUILayout.BeginHorizontal ("",skin.customStyles[1]);
        GUILayout.Label ("E-Mail");
        email = GUILayout.TextField (email,35,GUILayout.Width(280),GUILayout.Height(40));
        GUILayout.EndHorizontal ();
        GUILayout.Space (4);
        GUILayout.BeginHorizontal ("",skin.customStyles[1]);
        GUILayout.Label ("Senha");
        password = GUILayout.PasswordField(password,"*"[0],20,GUILayout.Width(280),GUILayout.Height(40));
        GUILayout.EndHorizontal ();
        GUILayout.FlexibleSpace ();
        if(GUILayout.Button("Registrar-se",GUILayout.Height(50))){
            Log = "";
            RequestRegister();
        }
        if(GUILayout.Button("Voltar",GUILayout.Height(50))){
            Log = "";
            LoginMode = lMode.login;
        }
    }
    void RequestRegister(){
        if (name.Length < 1) {
            Log = "Preencha o campo do Usuário.";
        }else{
            if(email.Length < 1){
                Log = "Preencha o campo do E-Mail.";
            }else{
                if(password.Length < 1){
                    Log = "Preencha o campo da Senha.";
                }else{
                    WWWForm register = new WWWForm();
                    register.AddField("user",name);
                    register.AddField("pass",password);
                    register.AddField("email",email);
                    WWW w = new WWW("http://nfx.comuv.com/register.php",register);
                    StartCoroutine(RequestRegisterInformations(w));
                }
            }
        }
    }
    void RequestLogin(){
        Log = "";
        if (user.Length < 1) {
            Log = "Preencha o campo do usuario";
        }else{
            if(pass.Length < 1){
                Log = "Preencha o campo da senha";
            }else{
                WWWForm login = new WWWForm();
                login.AddField("user",user);
                login.AddField("pass",pass);
                WWW w = new WWW("http://nfx.comuv.com/Login.php",login);
                StartCoroutine(RequestLoginInformations(w));
            }
        }
    }
    IEnumerator RequestLoginInformations(WWW w){
        yield return w;
        if (w.error == null) {
            Log = w.text;
        }
    }
    IEnumerator RequestRegisterInformations(WWW w){
        yield return w;
        if (w.error == null) {
            Log = w.text;
            if(Log == "Conta criada com sucesso!"){
                user = name;
                pass = password;
                name = "";
                password = "";
                LoginMode = lMode.login;
            }
        }
    }
}
 

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.