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

8
Assets/Resources.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bcb514437f9c35faaac228c5b6583838
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

Before

Width:  |  Height:  |  Size: 261 KiB

After

Width:  |  Height:  |  Size: 261 KiB

View File

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 257 KiB

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);
}