More work on spelling bee
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -19,53 +20,74 @@ public class Theme {
|
||||
|
||||
public class SpellingBeeController : MonoBehaviour {
|
||||
private string[] words;
|
||||
private int currentIndex;
|
||||
private string currentWord;
|
||||
|
||||
private ThemeList themeList;
|
||||
private Theme currentTheme;
|
||||
private List<GameObject> letters;
|
||||
private GameObject[] letters;
|
||||
|
||||
public Image image;
|
||||
public string inputString;
|
||||
public TMP_InputField input;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
loadJson();
|
||||
currentTheme = themeList.themes[0];
|
||||
|
||||
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);
|
||||
changeWord(randomWord);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
/*
|
||||
int randomIndex = UnityEngine.Random.Range(0, words.Length - 1);
|
||||
string randomWord = words[randomIndex];
|
||||
void Update() {
|
||||
if (input.text.Length > 0) {
|
||||
if (Char.ToUpper(input.text[0]) == Char.ToUpper(currentWord[currentIndex]) && input.text.Length == 1) {
|
||||
letters[currentIndex].GetComponent<Image>().color = Color.green;
|
||||
input.text = "";
|
||||
currentIndex++;
|
||||
|
||||
changeSprite(randomWord);
|
||||
if (currentIndex >= currentWord.Length) {
|
||||
for (int i = 0; i < currentWord.Length; i++) {
|
||||
Destroy(letters[i]);
|
||||
}
|
||||
|
||||
Debug.Log(randomWord);
|
||||
*/
|
||||
StartCoroutine(Wait());
|
||||
SetRandomWord();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void changeWord(string word) {
|
||||
int length = word.Length;
|
||||
|
||||
int center = 960;
|
||||
int canvasWidth = 1920;
|
||||
int maxWidth = 1080;
|
||||
|
||||
int[] xvalues = new int[length];
|
||||
|
||||
int spacing = maxWidth / (length - 1);
|
||||
|
||||
letters = new GameObject[length];
|
||||
int[] xvalues = new int[length];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
xvalues[i] = (canvasWidth - maxWidth) / 2 + i * spacing;
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
GameObject colorBox = new GameObject("Image with Text");
|
||||
GameObject colorBox = new GameObject("Letter box");
|
||||
colorBox.transform.SetParent(gameObject.transform);
|
||||
letters[i] = colorBox;
|
||||
|
||||
// Add an Image component to the new GameObject
|
||||
Image background = colorBox.AddComponent<Image>();
|
||||
@@ -106,4 +128,8 @@ public class SpellingBeeController : MonoBehaviour {
|
||||
themeList = JsonUtility.FromJson<ThemeList>(jsonString);
|
||||
words = themeList.themes[UnityEngine.Random.Range(0, themeList.themes.Length - 1)].words;
|
||||
}
|
||||
|
||||
IEnumerator Wait() {
|
||||
yield return new WaitForSecondsRealtime(2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user