Read words into list on startup
This commit is contained in:
29
Assets/Scripts/SpellingBeeController.cs
Normal file
29
Assets/Scripts/SpellingBeeController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class SpellingBeeController : MonoBehaviour
|
||||
{
|
||||
private List<string> lines;
|
||||
// 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);
|
||||
|
||||
string line = "";
|
||||
while ((line = reader.ReadLine()) != null) {
|
||||
lines.Add(line);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
int randomIndex = UnityEngine.Random.Range(0, lines.Count);
|
||||
string randomWord = lines[randomIndex];
|
||||
|
||||
Debug.Log(randomWord);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user