Write comments; some cleanup
This commit is contained in:
@@ -6,11 +6,13 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// JSON structure containing all themes/words
|
||||
[System.Serializable]
|
||||
public class ThemeList {
|
||||
public Theme[] themes;
|
||||
}
|
||||
|
||||
// Object representing part of the JSON containing word data
|
||||
[System.Serializable]
|
||||
public class Theme {
|
||||
public string name;
|
||||
@@ -18,17 +20,29 @@ public class Theme {
|
||||
public string[] words;
|
||||
}
|
||||
|
||||
public class SpellingBeeController : MonoBehaviour {
|
||||
public class SpellingBeeController : MonoBehaviour {
|
||||
// All of the words that can be used in this session
|
||||
private string[] words;
|
||||
|
||||
// Where we currently are in the word
|
||||
private int currentIndex;
|
||||
|
||||
// The word that is currently being spelled
|
||||
private string currentWord;
|
||||
|
||||
// All of the available themes
|
||||
private ThemeList themeList;
|
||||
|
||||
// The theme we are currently using
|
||||
private Theme currentTheme;
|
||||
|
||||
// The GameObjects representing the letters
|
||||
private GameObject[] letters;
|
||||
|
||||
// The Image component for displaying the appropriate sprite
|
||||
public Image image;
|
||||
public string inputString;
|
||||
|
||||
// The input field for testing purposes
|
||||
public TMP_InputField input;
|
||||
|
||||
// Start is called before the first frame update
|
||||
@@ -39,18 +53,6 @@ public class SpellingBeeController : MonoBehaviour {
|
||||
SetRandomWord();
|
||||
}
|
||||
|
||||
void SetRandomWord() {
|
||||
currentIndex = 0;
|
||||
|
||||
int randomIndex = UnityEngine.Random.Range(0, words.Length - 1);
|
||||
string randomWord = words[randomIndex];
|
||||
|
||||
letters = new GameObject[randomWord.Length];
|
||||
currentWord = randomWord;
|
||||
changeSprite(randomWord);
|
||||
changeWord(randomWord);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if (input.text.Length > 0) {
|
||||
@@ -71,7 +73,21 @@ public class SpellingBeeController : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void changeWord(string word) {
|
||||
// Pick a new random word from words and initialize the needed variables
|
||||
void SetRandomWord() {
|
||||
currentIndex = 0;
|
||||
|
||||
int randomIndex = UnityEngine.Random.Range(0, words.Length - 1);
|
||||
string randomWord = words[randomIndex];
|
||||
|
||||
letters = new GameObject[randomWord.Length];
|
||||
currentWord = randomWord;
|
||||
changeSprite(randomWord);
|
||||
displayWord(randomWord);
|
||||
}
|
||||
|
||||
// Displays the word that needs to be spelled
|
||||
void displayWord(string word) {
|
||||
int length = word.Length;
|
||||
int canvasWidth = 1920;
|
||||
int maxWidth = 1080;
|
||||
@@ -112,6 +128,7 @@ public class SpellingBeeController : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
// Change the image that is being displayed
|
||||
void changeSprite(string spriteName) {
|
||||
Image imageComponent = image.GetComponent<Image>();
|
||||
|
||||
@@ -122,6 +139,7 @@ public class SpellingBeeController : MonoBehaviour {
|
||||
image.sprite = sprite;
|
||||
}
|
||||
|
||||
// Loads the JSON file containing all of the themes
|
||||
void loadJson() {
|
||||
TextAsset themeJson = Resources.Load<TextAsset>("SpellingBee/words");
|
||||
string jsonString = themeJson.text;
|
||||
|
||||
Reference in New Issue
Block a user