Small refactor to use Resource folder

This commit is contained in:
lvrossem
2023-02-28 12:44:56 +01:00
parent 4fdfd0da84
commit 5652259e4e
10 changed files with 15 additions and 12 deletions

View File

@@ -5,24 +5,19 @@ using UnityEngine;
public class SpellingBeeController : MonoBehaviour
{
private List<string> lines;
private string[] words;
// Start is called before the first frame update
void Start() {
lines = new List<string>();
string path = "Assets/SpellingBee/words.txt";
StreamReader reader = new StreamReader(path);
void Start() {
TextAsset textFile = Resources.Load<TextAsset>("SpellingBee/words");
string fileContents = textFile.text;
string line = "";
while ((line = reader.ReadLine()) != null) {
lines.Add(line);
}
words = fileContents.Split('\n');
}
// Update is called once per frame
void Update() {
int randomIndex = UnityEngine.Random.Range(0, lines.Count);
string randomWord = lines[randomIndex];
int randomIndex = UnityEngine.Random.Range(0, words.Length - 1);
string randomWord = words[randomIndex];
Debug.Log(randomWord);
}