Welcome, Guest
Username: Password: Remember me

TOPIC: Button to target input field linked to I2Loc?

Button to target input field linked to I2Loc? 4 months 4 weeks ago #3130

  • jimmyt3d
  • jimmyt3d's Avatar
  • Offline
  • Senior Member
  • Posts: 46
  • Thank you received: 1
  • Karma: 1
Hi Frank,
I hope you are well.
A couple of years ago you assisted with a piece of code to make a password Input Field look to the I2Loc Language Source to check for the password (to enable the password to be updated remotely via the spreadsheet). Here is the script (currently in the 'On End Edit (String)' field of the Input Field.
using UnityEngine;
using System.Collections;

public class PasswordInput2 : MonoBehaviour {

		public GameObject myObject; //Wrong password message
	public GameObject myObject2; //Correct password message

	public void PassWordCheck(string incomingPassword)
	{
		var RealPassword = I2.Loc.ScriptLocalization.Get("MapPW", false);


		if (incomingPassword == RealPassword)
		{
			myObject.SetActive(false);
			myObject2.SetActive(true);
								}
		else
		{
			myObject.SetActive(true);
			myObject2.SetActive(false);
	}
}
}

This has always worked perfectly, however I wish to make a slight change to how it works.
Now I want to have a 'LOGIN' button that the user can click once they have put their password in, then when this button is clicked I want it to check the Input Field for the password and then respond in the same way it does now. Essentially I want the current behaviour migrated to a button instead of the Input Field itself (too many issues with the password being 'entered' if you happen to click away from the input field due to the way Unity handles focus, therefore I want my 'Incorrect Password' messages only to appear after a 'Login' button has been pressed).
I assume this script needs to be added to the OnClick of the button instead of the Input field, but I am unsure how to make it look to the Input Field from the button.

Any help would be great, I'm not a coder so if you could update the script for me that would be much appreciated!

Unity 5.6.4f1 - I2Loc 2.7.0f1

Thanks
The administrator has disabled public write access.

Button to target input field linked to I2Loc? 4 months 4 weeks ago #3131

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 1139
  • Thank you received: 243
  • Karma: 72
Hi,
The code is mostly the same, you just need to add a reference to the InputField and OnClick just grabs its text and calls the PassWordCheck function:
using UnityEngine;
using System.Collections;

public class PasswordInput2 : MonoBehaviour
{
    public GameObject myObject; //Wrong password message
    public GameObject myObject2; //Correct password message
    public UnityEngine.UI.InputField myPasswordInputField;

    public void OnClick()
    {
        PassWordCheck(myPasswordInputField.text);
    }

    public void PassWordCheck(string incomingPassword)
    {
        var RealPassword = I2.Loc.ScriptLocalization.Get("MapPW", false);


        if (incomingPassword == RealPassword)
        {
            myObject.SetActive(false);
            myObject2.SetActive(true);
        }
        else
        {
            myObject.SetActive(true);
            myObject2.SetActive(false);
        }
    }
}

Assign that script to the gameobject and drag the inputField to the myPasswordInputField property.
Then, in the button, add an OnClick and assign the OnClick function.

Hope that helps,
Frank
Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out
The administrator has disabled public write access.

Button to target input field linked to I2Loc? 4 months 3 weeks ago #3132

  • jimmyt3d
  • jimmyt3d's Avatar
  • Offline
  • Senior Member
  • Posts: 46
  • Thank you received: 1
  • Karma: 1
That works a treat - thanks a lot Frank.
The administrator has disabled public write access.
Time to create page: 0.150 seconds
Template by JoomlaShine