Why Doesn't It Works

Could you please take a look at this script? I think i did everything right but i can’t take result…

public void ButtonCheck()
    {
       
        if(Name==null || Password==null || PassAgain == null)
        {
            Wrong.SetActive(true);
        }

        if(Name!=null && Password!=null && PassAgain != null)
        {
            if (Password == PassAgain)
            {
                SceneManager.LoadScene("LoginScreen");
            }
            if (Password != PassAgain)
            {
                Wrong.SetActive(true);
            }
        }

Even if i don’t take any errors in Visual Studio it doesn’t work…
(Also added this script to a empty GameObject and used OnClick.

You’re missing a closing bracket for the function. You’re also only checking if the strings are null but not if they’re empty. If they’re all empty they will compare and be the same. Null and empty are not the same thing when it comes to a string. You could also condense that down a bit.

public string fullName;
public string password;
public string passAgain;
public GameObject wrong;

public void ButtonCheck () {
      
    if (string.IsNullOrEmpty (fullName)) wrong.SetActive (true);
    else if (string.IsNullOrEmpty (password)) wrong.SetActive (true);
    else if (string.IsNullOrEmpty (passAgain)) wrong.SetActive (true);
    else if (password == passAgain) print ("Correct");
    else if (password != passAgain) wrong.SetActive (true);

}

It worked flawlessly, thank for your help bro <3<3<3

1 Like