I need to make a reference to “list 1” which is my text file but I do not know how please help
c+ using UnityEngine; using System.Collections; using UnityEngine.UI;
public class opena: MonoBehaviour {
public GameObject inputField;
public string wordsFile = "c:\\file.list1.txt"; // EDIT THIS TO POINT TO YOUR FILE OF 60,000 WORDS
5.
void Start() {
inputField = GameObject.Find("InputField"); //This is where you assign the input field object so you can access your inputField component
inputField.GetComponent < InputField > (wordsFile).text = "list1"; //This makes it so the input field starts with nothing in it.
10. string[] array = File.ReadLines().ToArray(); // This will load a text file into an array of strings
var hash = new HashSet < string > (array); // this converts the string array to a HashSet, could also use a dictionary for slightly better speed
}
void Update() {
15. if (Input.GetKeyDown(KeyCode.Return)) { // Check for if they have hit enter
string input = inputField.GetComponent < InputField > ().text; // set a string to be what they entered
if (hash.Contains(input)) // check if the HashSet contains the code they entered
20. {
// If they get here the code is correct
// i.e its in the list of 60,000 words
// do SOMETHING
} else {
25. // IF they get here... then they entered a WRONG CODe
// i.e not in the list of 60k words
// DO SOMETHING
}
}
30. }
}