Finally manage to render a word

This commit is contained in:
lvrossem
2023-03-01 21:16:26 +01:00
parent ecd24dce04
commit 95b17fff22
2 changed files with 228 additions and 188 deletions

View File

@@ -1,183 +1,183 @@
{
"themes" :[
{
"name": "Basis",
"description": "Alledaagse woordenschat",
"words": [
"hallo",
"welkom",
"goeiemorgen",
"slaapwel",
"links",
"rechts",
"goed zo",
"ja",
"nee",
"bravo",
"stop",
"dank u",
"alstublieft"
]
},
{
"name": "Familie en vrienden",
"description": "🎵 I'll be there for you 🎵",
"words": [
"baby",
"jongen",
"meisje",
"man",
"vrouw",
"broer",
"zus",
"ouders",
"oma",
"opa",
"neef",
"nicht",
"familie",
"vrienden",
"tante",
"nonkel"
]
},
{
"name": "Huis- en boerderijdieren",
"description": "Honden, katten, en nog veel meer...",
"words": [
"kat",
"hond",
"konijn",
"cavia",
"paard",
"varken",
"koe",
"lama",
"alpaca",
"kip",
"schaap",
"ram",
"goudvis",
"schildpad",
"papegaai"
]
},
{
"name": "In het wild",
"description": "Van aap tot zebra",
"words": [
"vos",
"tijger",
"lynx",
"wolf",
"giraf",
"leeuw",
"dolfijn",
"walvis",
"haai",
"hert",
"olifant",
"kangoeroe",
"panda",
"slang",
"zebra",
"aap"
]
},
{
"name": "Hobbies",
"description": "Een leuke woensdagnamiddag",
"words": [
"atletiek",
"basketbal",
"boksen",
"golf",
"gymnastiek",
"hockey",
"judo",
"paardrijden",
"quizzen",
"roeien",
"schaatsen",
"tennis",
"voetbal",
"volleybal",
"wielrennen",
"zeilen",
"zwemmen"
]
},
{
"name": "Gebouwen en plaatsen",
"description": "Made in Belgium",
"words": [
"huis",
"tent",
"toren",
"appartement",
"ziekenhuis",
"winkel",
"station",
"zwembad",
"sporthal",
"theater",
"bioscoop",
"stadion",
"park",
"speelpleintje",
"bibliotheek"
]
},
{
"name": "Fruit en groenten",
"description": "Gezonde vitamines",
"words": [
"aardbei",
"broccoli",
"kiwi",
"citroen",
"papaja",
"paprika",
"tomaat",
"komkommer",
"kers",
"peer",
"appel",
"perzik",
"druiven",
"wortel",
"mais",
"kool"
]
},
{
"name": "Landen",
"description": "Van Afrika tot in Amerika",
"words": [
"belgie",
"nederland",
"frankrijk",
"duitsland",
"ierland",
"verenigd koninkrijk",
"griekenland",
"finland",
"zweden",
"noorwegen",
"spanje",
"portugal",
"italie",
"australie",
"colombia",
"canada",
"india",
"japan",
"china",
"rusland",
"qatar",
"europa"
]
}
"themes": [
{
"name": "Basis",
"description": "Alledaagse woordenschat",
"words": [
"hallo",
"welkom",
"goeiemorgen",
"slaapwel",
"links",
"rechts",
"goed zo",
"ja",
"nee",
"bravo",
"stop",
"dank u",
"alstublieft"
]
},
{
"name": "Familie en vrienden",
"description": "🎵 I'll be there for you 🎵",
"words": [
"baby",
"jongen",
"meisje",
"man",
"vrouw",
"broer",
"zus",
"ouders",
"oma",
"opa",
"neef",
"nicht",
"familie",
"vrienden",
"tante",
"nonkel"
]
},
{
"name": "Huis- en boerderijdieren",
"description": "Honden, katten, en nog veel meer...",
"words": [
"kat",
"hond",
"konijn",
"cavia",
"paard",
"varken",
"koe",
"lama",
"alpaca",
"kip",
"schaap",
"ram",
"goudvis",
"schildpad",
"papegaai"
]
},
{
"name": "In het wild",
"description": "Van aap tot zebra",
"words": [
"vos",
"tijger",
"lynx",
"wolf",
"giraf",
"leeuw",
"dolfijn",
"walvis",
"haai",
"hert",
"olifant",
"kangoeroe",
"panda",
"slang",
"zebra",
"aap"
]
},
{
"name": "Hobbies",
"description": "Een leuke woensdagnamiddag",
"words": [
"atletiek",
"basketbal",
"boksen",
"golf",
"gymnastiek",
"hockey",
"judo",
"paardrijden",
"quizzen",
"roeien",
"schaatsen",
"tennis",
"voetbal",
"volleybal",
"wielrennen",
"zeilen",
"zwemmen"
]
},
{
"name": "Gebouwen en plaatsen",
"description": "Made in Belgium",
"words": [
"huis",
"tent",
"toren",
"appartement",
"ziekenhuis",
"winkel",
"station",
"zwembad",
"sporthal",
"theater",
"bioscoop",
"stadion",
"park",
"speelpleintje",
"bibliotheek"
]
},
{
"name": "Fruit en groenten",
"description": "Gezonde vitamines",
"words": [
"aardbei",
"broccoli",
"kiwi",
"citroen",
"papaja",
"paprika",
"tomaat",
"komkommer",
"kers",
"peer",
"appel",
"perzik",
"druiven",
"wortel",
"mais",
"kool"
]
},
{
"name": "Landen",
"description": "Van Afrika tot in Amerika",
"words": [
"belgie",
"nederland",
"frankrijk",
"duitsland",
"ierland",
"verenigd koninkrijk",
"griekenland",
"finland",
"zweden",
"noorwegen",
"spanje",
"portugal",
"italie",
"australie",
"colombia",
"canada",
"india",
"japan",
"china",
"rusland",
"qatar",
"europa"
]
}
]
}

View File

@@ -1,35 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class ThemeList
{
public class ThemeList {
public Theme[] themes;
}
[System.Serializable]
public class Theme
{
public class Theme {
public string name;
public string description;
public string[] words;
}
public class SpellingBeeController : MonoBehaviour
{
public class SpellingBeeController : MonoBehaviour {
private string[] words;
private ThemeList themeList;
private Theme currentTheme;
private List<GameObject> letters;
public Image image;
// Start is called before the first frame update
void Start() {
loadJson();
theme = themeList[0];
changeSprite("kiwi");
currentTheme = themeList.themes[0];
changeSprite("kiwi");
changeWord("kiwi");
}
// Update is called once per frame
@@ -45,7 +46,46 @@ public class SpellingBeeController : MonoBehaviour
}
void changeWord(string word) {
for (int i = 0; i < word.Length; i++) {
/*
Debug.Log("Yello");
GameObject letterBox = new GameObject();
Debug.Log("Yello");
// Add an Image component to the new GameObject
Image image = letterBox.AddComponent<Image>();
Debug.Log("Yello");
letterBox.color = Color.black;
Debug.Log("Yello");
// Add a Text component to the new GameObject
Text textComponent = letterBox.AddComponent<Text>();
textComponent.text = Char.ToString(word[i]);
*/
GameObject colorBox = new GameObject("Image with Text");
colorBox.transform.SetParent(gameObject.transform);
// Add an Image component to the new GameObject
Image background = colorBox.AddComponent<Image>();
background.color = Color.red;
background.sprite = UnityEditor.AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd");
// Create a new child GameObject to hold the Text component
GameObject letterObject = new GameObject("Text");
letterObject.transform.SetParent(colorBox.transform);
// Add a Text component to the new child GameObject
Text letterComponent = letterObject.AddComponent<Text>();
letterComponent.text = Char.ToString(Char.ToUpper(word[i]));
letterComponent.alignment = TextAnchor.MiddleCenter;
letterComponent.fontSize = 60;
// Set the font of the Text component
letterComponent.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
// Set the position of the parent GameObject
colorBox.transform.position = new Vector2(50 + i * 200, 350);
}
}
void changeSprite(string spriteName) {