Switching between Panels with Script (Open/Close)

Hello together :slight_smile:

I have got one little problem with switching the panels in my case.
With the OneClick event integrated from Unity it´s really easy. But in this case the next screen should only be shown of course, when the user types in correct user data (otherwise exception as you see in the code).

I mean it cannot be that hard, to set the next panel active and make the current one inactive, when the response is true…

Here the code:

    public void SignInUserButton() {
        SignInUser(SignInEmail.text, SignInPW.text);
    }
    //LogIn User
    private void SignInUser(string email, string password) {
        string userData = "{\"email\":\"" + email + "\",\"password\":\"" + password + "\",\"returnSecureToken\":true}";
        RestClient.Post<SignResponse>("https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + AuthKey, userData).Then(
            response => {
                idToken = response.idToken;
                localId = response.localId;

                // At this point I want to open the next Panel and close this Panel....

                GetUserInformation();
            }).Catch(error => {
                Debug.Log(error);
            });
    }

How would you go on? What would you recommend?
Thank you in advance :slight_smile:

thisPanel.SetActive(false);
theNextPanel.SetActive(true);

so I made a PanelOpener Class and assigned the Panels (Prefabs) to the fields.

public class PanelOpener : MonoBehaviour
{
    public GameObject AccountCreationScreen;
    public GameObject LogInScreen;

}

and in the code I put:

PanelOpener opener = new PanelOpener();
                opener.AccountCreationScreen.SetActive(false);
                opener.LogInScreen.SetActive(true);

Unfortunately I get an error message: NullReferenceException: Object reference not set to an instance of an object…
You know how to solve it?

Oh my goodness… Happy Monday, Happy New Year.

The answer is always the same… ALWAYS. It is the single most common error ever. Don’t waste your life on this problem. Instead, learn how to fix it fast… it’s EASY!!

Some notes on how to fix a NullReferenceException error in Unity3D

  • also known as: Unassigned Reference Exception
  • also known as: Missing Reference Exception

http://plbm.com/?p=221

The basic steps outlined above are:

  • Identify what is null
  • Identify why it is null
  • Fix that.

Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.

This is the kind of mindset and thinking process you need to bring to this problem:

https://discussions.unity.com/t/814091/4

Step by step, break it down, find the problem.