this code checks a word input against the list “words” . … but how do I add multiple different if statements one rite after the other, so user must get 10 code words correct ? each correct word will allow user to next code word, and until he reaches action will be taken , door to player opens etc whatever… this code works with one check the “words” list I have more statements needed
so when user inputs correct code an action is taken but what if I wanted to add another set of code after the first code word, so multiple code words . each word checked from different lists if player types correct 1st word it then goes to the 2nd list and checks for the next typed input word,
so for example
I have 10 lists each test with different code words
and after the 1st correct word is typed user then must input the next codeword and then the next etc
so
10 lists to pull from and so 10 codewords
I thought about pasting the code after that code in same script since its in the same input field box but I think its wiser to just add more if /else statements
correct?
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class werda : MonoBehaviour
{
public GameObject inputField;
public string wordsFile;
private HashSet<string> hash;
void Start()
{
wordsFile = "C:\\Users\
ew\Pictures\words2.txt";
//wordsFile = Application.dataPath + “/words2.txt”;
inputField = GameObject.Find(“InputField”); //This is where you assign the input field object so you can access your inputField component
inputField.GetComponent ().text = “”; //This makes it so the input field starts with nothing in it.
string[] array = File.ReadAllLines// This will load a text file into an array of strings
Debug.Log("entries in array: " array.Length);
hash = new HashSet < > (array); // this converts the string array to a HashSet, could also use a dictionary for slightly better speed
Debug.Log("entries in hash: " hash.Count);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.))
{
string input = inputField.GetComponent < > ().text; // set a string to be what they entered
Debug.Log("checking word: "input);
if (hash.Contains()) // check if the HashSet contains the code they entered
{
Debug.Log("word found");
// If they get here the code is correct magic door opens
// i.e its in the list of 60,000 words
// do SOMETHING
} else {
//Debug.Log("word NOT found");
Destroy (gameObject, 1 );
// IF they get here... then they entered a WRONG CODe , magic door closes
// i.e not in the list of 60k words
// DO SOMETHING
}
}
}
}