Z
Z
Zimaell2020-07-20 15:53:49
Unity
Zimaell, 2020-07-20 15:53:49

How to do authorization?

Made a sort of simple authorization (extra code removed)

spoiler
public class Authorization : MonoBehaviour{
..................
    void Start(){
        if(PlayerPrefs.HasKey("Login") && PlayerPrefs.HasKey("Password")){
            LoginField.text = PlayerPrefs.GetString("Login");
            PasswordField.text = PlayerPrefs.GetString("Password");
            EnterGame();
            }
        }

    public void EnterGame(){
        StartCoroutine(AuthorizationGame());
        }
    
    IEnumerator AuthorizationGame(){
        WWWForm form = new WWWForm();
        form.AddField( "login",         LoginField.text);
        form.AddField( "password",      PasswordField.text);
        UnityWebRequest www = UnityWebRequest.Post(ServerIpAddress, form);
        yield return www.SendWebRequest();
        if (www.isNetworkError || www.isHttpError){
            Answer="error";
            }else{
                Answer=www.downloadHandler.text;
......................
                PlayerPrefs.SetString("Login",      LoginField.text);
                PlayerPrefs.SetString("Password",   PasswordField.text);
                SceneManager.LoadScene("Game");
                }
        }
    }

If you run the test in unity itself, then everything works, entering a login and password, if you re-enter, the game scene is immediately loaded as the data is saved.
But now I’m doing a PC version, compiling and running, the start screen with entering the fields, but after clicking on enter nothing happens ...
Although if you enter it incorrectly or there is no connection with the server, then the necessary error appears in the window below, but nothing at all.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Glebov, 2020-07-30
@GLeBaTi

Zimaell ,
1) Where do you see errors? You need to look in the log file that is next to the exe, and not in the editor.
2) Add Debug.Log("1...n") between lines of code to understand which step is passing and which is not.
3) Add a response log from the server (data and response code)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question