используйте if-else
!В настоящее время оба оператора выполняются
public void ShowPassword()
{
if (passwordInput.inputType == UIInput.InputType.Standard)
{
passwordInput.inputType = UIInput.InputType.Password;
passwordInput.UpdateLabel();
}
// after the first statement was executed this will allways be true
// and will revert the change right ahead
if (passwordInput.inputType == UIInput.InputType.Password)
{
passwordInput.inputType = UIInput.InputType.Standard;
passwordInput.UpdateLabel();
}
}
, поэтому результат всегда равен passwordInput.inputType = UIInput.InputType.Standard
независимо от того, что было раньше.
Вместо этого используйте
if (passwordInput.inputType == UIInput.InputType.Standard)
{
passwordInput.inputType = UIInput.InputType.Password;
passwordInput.UpdateLabel();
}
// execute the second check only if the frírst condition wasn't met before
else if (passwordInput.inputType == UIInput.InputType.Password)
{
passwordInput.inputType = UIInput.InputType.Standard;
passwordInput.UpdateLabel();
}
Иличтобы было еще проще читать, я бы сделал
public void TooglePasswordVisablilty()
{
bool isCurrentlyPassword = passwordInput.inputType == UIInput.InputType.Password;
passwordInput.inputType = isCurrentlyPassword ? UIInput.InputType.Standard : UIInput.InputType.Password;
passwordInput.UpdateLabel();
}