Small refactor to use Resource folder
This commit is contained in:
8
Assets/Resources.meta
Normal file
8
Assets/Resources.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcb514437f9c35faaac228c5b6583838
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
Before Width: | Height: | Size: 261 KiB After Width: | Height: | Size: 261 KiB |
|
Before Width: | Height: | Size: 257 KiB After Width: | Height: | Size: 257 KiB |
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user