- Home /
Input Field text history/previous
Hi, i'm trying to make text history with Single line, because the script don't work with Multi line new line, so i was trying to make it with single line, i mean, when i type the pass, so the string pass will be moved up and can't be modifed but i don't know how to do this, thanks for help.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class asd : MonoBehaviour {
[SerializeField]
private InputField nameInputField = null;
public GameObject text1;
public Text txt;
public string pass;
void Start() {
pass = "mypass";
text1 = GameObject.Find ("Text1");
txt = text1.GetComponent<Text>();
}
private void Update()
{
// Add listener to catch the submit
InputField.SubmitEvent submitEvent = new InputField.SubmitEvent();
submitEvent.AddListener(SubmitName);
nameInputField.onEndEdit = submitEvent;
}
private void SubmitName(string name)
{
if (nameInputField.text == pass) {
txt.text = "true";
nameInputField.lineType = InputField.LineType.MultiLineNewline;
nameInputField.text = pass;
nameInputField.lineType = InputField.LineType.SingleLine;
nameInputField.text = "";
} else if (nameInputField.text != pass) {
txt.text = "false";
nameInputField.text = "";
}
}
}
Comment