Search Unity

script does not work with IOs

Discussion in 'Scripting' started by Nabil_fx, Oct 14, 2015.

  1. Nabil_fx

    Nabil_fx

    Joined:
    Nov 9, 2013
    Posts:
    124
    I have a script for registration and login, but in the iphone app, the buttons works, but the script does not work, what can be wrong?
    here is the script.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LoginSystem : MonoBehaviour {
    5.  
    6.     public enum lMode{login,register};
    7.     public lMode LoginMode;
    8.  
    9.     public GUISkin skin;
    10.     //login
    11.     private string user = "";
    12.     private string pass = "";
    13.     private bool   remember;
    14.     private int    boolstatus;
    15.     //register
    16.     private string name = "";
    17.     private string password = "";
    18.     private string email = "";
    19.  
    20.     public string Log;
    21.     public Texture LogTexture;
    22.  
    23.     public string sceneMap;
    24.  
    25.     void Start () {
    26.         boolstatus = PlayerPrefs.GetInt("bs");
    27.         if (boolstatus == 1) {
    28.             remember = true;
    29.         }else{
    30.             remember = false;
    31.         }
    32.         if (remember == true) user = PlayerPrefs.GetString ("login");
    33.     }
    34.  
    35.     void Update () {
    36.         if (remember == true) {
    37.             PlayerPrefs.SetString("login",user);
    38.             boolstatus = 1;
    39.             PlayerPrefs.SetInt("bs",boolstatus);
    40.         }else{
    41.             boolstatus = 0;
    42.             PlayerPrefs.SetInt("bs",boolstatus);
    43.         }
    44.     }
    45.     void OnGUI(){
    46.         GUI.skin = skin;
    47.  
    48.         GUI.DrawTexture (new Rect (Screen.width / 2 -288, Screen.height / 2 -200, 576, 500), LogTexture);
    49.  
    50.         GUILayout.BeginArea(new Rect(Screen.width/2 -180,Screen.height/2 +178,380,40),"","");
    51.         GUILayout.Label ("<color=black>"+Log+"</color>");
    52.         GUILayout.EndArea();
    53.  
    54.         if (LoginMode == lMode.login) {
    55.             GUILayout.BeginArea(new Rect(Screen.width/2 -190,Screen.height/2 -135,380,270),"","Box");
    56.             LoginGUI();
    57.             GUILayout.EndArea();
    58.         }else if (LoginMode == lMode.register){
    59.             GUILayout.BeginArea(new Rect(Screen.width/2 -190,Screen.height/2 -135,380,300),"","Box");
    60.             RegisterGUI();
    61.             GUILayout.EndArea();
    62.         }
    63.     }
    64.     void LoginGUI(){
    65.         GUILayout.BeginHorizontal ("",skin.customStyles[1]);
    66.         GUILayout.Label ("<size=21>Usuário</size>");
    67.         user = GUILayout.TextField (user,15,GUILayout.Width(280),GUILayout.Height(40));
    68.         GUILayout.EndHorizontal ();
    69.         GUILayout.Space (4);
    70.         GUILayout.BeginHorizontal ("",skin.customStyles[1]);
    71.         GUILayout.Label ("Senha");
    72.         pass = GUILayout.PasswordField(pass,"*"[0],20,GUILayout.Width(280),GUILayout.Height(40));
    73.         GUILayout.EndHorizontal ();
    74.         GUILayout.BeginHorizontal ();
    75.         GUILayout.FlexibleSpace ();
    76.         GUILayout.Label ("<size=21>Lembrar Usuário</size>",GUILayout.Width(180));
    77.         remember = GUILayout.Toggle (remember,"", GUILayout.Width (40), GUILayout.Height (40));
    78.         GUILayout.EndHorizontal ();
    79.         GUILayout.FlexibleSpace ();
    80.         if(GUILayout.Button("Logar-se",GUILayout.Height(50))){
    81.             Log = "";
    82.             RequestLogin();
    83.         }
    84.         if(GUILayout.Button("Registrar-se",GUILayout.Height(50))){
    85.             Log = "";
    86.             LoginMode = lMode.register;
    87.         }
    88.     }
    89.     void RegisterGUI(){
    90.         GUILayout.BeginHorizontal ("",skin.customStyles[1]);
    91.         GUILayout.Label ("<size=21>Usuário</size>");
    92.         name = GUILayout.TextField (name,15,GUILayout.Width(280),GUILayout.Height(40));
    93.         GUILayout.EndHorizontal ();
    94.         GUILayout.Space (4);
    95.         GUILayout.BeginHorizontal ("",skin.customStyles[1]);
    96.         GUILayout.Label ("E-Mail");
    97.         email = GUILayout.TextField (email,35,GUILayout.Width(280),GUILayout.Height(40));
    98.         GUILayout.EndHorizontal ();
    99.         GUILayout.Space (4);
    100.         GUILayout.BeginHorizontal ("",skin.customStyles[1]);
    101.         GUILayout.Label ("Senha");
    102.         password = GUILayout.PasswordField(password,"*"[0],20,GUILayout.Width(280),GUILayout.Height(40));
    103.         GUILayout.EndHorizontal ();
    104.         GUILayout.FlexibleSpace ();
    105.         if(GUILayout.Button("Registrar-se",GUILayout.Height(50))){
    106.             Log = "";
    107.             RequestRegister();
    108.         }
    109.         if(GUILayout.Button("Voltar",GUILayout.Height(50))){
    110.             Log = "";
    111.             LoginMode = lMode.login;
    112.         }
    113.     }
    114.     void RequestRegister(){
    115.         if (name.Length < 1) {
    116.             Log = "Preencha o campo do Usuário.";
    117.         }else{
    118.             if(email.Length < 1){
    119.                 Log = "Preencha o campo do E-Mail.";
    120.             }else{
    121.                 if(password.Length < 1){
    122.                     Log = "Preencha o campo da Senha.";
    123.                 }else{
    124.                     WWWForm register = new WWWForm();
    125.                     register.AddField("user",name);
    126.                     register.AddField("pass",password);
    127.                     register.AddField("email",email);
    128.                     WWW w = new WWW("http://nfx.comuv.com/register.php",register);
    129.                     StartCoroutine(RequestRegisterInformations(w));
    130.                 }
    131.             }
    132.         }
    133.     }
    134.     void RequestLogin(){
    135.         Log = "";
    136.         if (user.Length < 1) {
    137.             Log = "Preencha o campo do usuario";
    138.         }else{
    139.             if(pass.Length < 1){
    140.                 Log = "Preencha o campo da senha";
    141.             }else{
    142.                 WWWForm login = new WWWForm();
    143.                 login.AddField("user",user);
    144.                 login.AddField("pass",pass);
    145.                 WWW w = new WWW("http://nfx.comuv.com/Login.php",login);
    146.                 StartCoroutine(RequestLoginInformations(w));
    147.             }
    148.         }
    149.     }
    150.     IEnumerator RequestLoginInformations(WWW w){
    151.         yield return w;
    152.         if (w.error == null) {
    153.             Log = w.text;
    154.         }
    155.     }
    156.     IEnumerator RequestRegisterInformations(WWW w){
    157.         yield return w;
    158.         if (w.error == null) {
    159.             Log = w.text;
    160.             if(Log == "Conta criada com sucesso!"){
    161.                 user = name;
    162.                 pass = password;
    163.                 name = "";
    164.                 password = "";
    165.                 LoginMode = lMode.login;
    166.             }
    167.         }
    168.     }
    169. }
    170.  
     
  2. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Sorry, I'm not sure I can help with that one.

    But I can say you'll get more responses if describe the issue in the thread title, rather than "need help". I learned that the hard way.