using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UI; [System.Serializable] public class ThemeList { public Theme[] themes; } [System.Serializable] public class Theme { public string name; public string description; public string[] words; } public class SpellingBeeController : MonoBehaviour { private string[] words; private ThemeList themeList; private Theme currentTheme; public Image image; // Start is called before the first frame update void Start() { loadJson(); theme = themeList[0]; changeSprite("kiwi"); } // Update is called once per frame void Update() { /* int randomIndex = UnityEngine.Random.Range(0, words.Length - 1); string randomWord = words[randomIndex]; changeSprite(randomWord); Debug.Log(randomWord); */ } void changeWord(string word) { } void changeSprite(string spriteName) { Image imageComponent = image.GetComponent(); // Load the new sprite from the Resources folder Debug.Log("SpellingBee/images/" + spriteName); Sprite sprite = Resources.Load("SpellingBee/images/" + spriteName); Debug.Log(sprite.pixelsPerUnit); // Set the new sprite as the Image component's source image image.sprite = sprite; } void loadJson() { TextAsset themeJson = Resources.Load("SpellingBee/words"); string jsonString = themeJson.text; Debug.Log(jsonString); themeList = JsonUtility.FromJson(jsonString); foreach (Theme theme in themeList.themes) { Debug.Log(theme.description); } } }