text code to unlock door 2D
Hi, I want to unlock a 2D door using a text code. If you enter a certain text, lets say "open", it opens the door. if you enter a other code lets say "hello" the door does not open. How do I do this?
I need this for a school project so I would really really like if you guys could help me.
Thanks!
Comment
Answer by Jessespike · Sep 12, 2016 at 03:28 PM
Create an InputField and attach a script that checks the text.
In the InputField's OnEndEdit, add the script's text check function.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class InputFieldKeywords : MonoBehaviour {
InputField inputField;
// Use this for initialization
void Awake () {
inputField = GetComponent<InputField>();
}
public void CheckText()
{
if (inputField.text == "open")
{
Debug.Log("door open");
// TODO unlock door
}
}
}