Allow user to enter words corresponding to symbols

This commit is contained in:
lvrossem
2023-03-16 17:23:50 +01:00
parent d81a04ff2a
commit 39618ab75c
3 changed files with 553 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -13,6 +14,11 @@ public class JustSignController : MonoBehaviour
/// </summary>
public Canvas canvas;
/// <summary>
/// The input field where the user can type his or her answer
/// </summary>
public TMP_InputField answerField;
/// <summary>
/// All of the words that can be used in this session
/// </summary>
@@ -63,7 +69,9 @@ public class JustSignController : MonoBehaviour
/// </summary>
private float lastSpawn;
// Start is called before the first frame update
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
themeList = ThemeLoader.LoadJson();
@@ -74,35 +82,42 @@ public class JustSignController : MonoBehaviour
SpawnNewSymbol();
}
// Update is called once per frame
/// <summary>
/// Update is called once per frame
/// </summary>
void Update()
{
if (answerField.text.ToLower() == activeWords[0]) {
DestroyRightmostSymbol();
answerField.text = "";
}
if (activeSymbols[0].GetComponent<RectTransform>().localPosition.x > -trackX) {
DestroyRightmostSymbol();
}
float currentTime = Time.time;
if (currentTime - lastSpawn > 1) {
lastSpawn = currentTime;
SpawnNewSymbol();
}
if (activeSymbols[0].GetComponent<RectTransform>().localPosition.x > -trackX) {
Debug.Log("LENGTH BEFORE:");
Debug.Log(activeWords.Count);
activeWords.RemoveAt(0);
Debug.Log("LENGTH AFTER:");
Debug.Log(activeWords.Count);
GameObject symbol = activeSymbols[0];
activeSymbols.RemoveAt(0);
Destroy(symbol);
}
//Debug.Log(activeWords.Count);
Debug.Log(activeWords.Count);
foreach (GameObject symbol in activeSymbols) {
RectTransform rectTransform = symbol.GetComponent<RectTransform>();
rectTransform.localPosition = new Vector3(rectTransform.localPosition.x + Time.deltaTime * moveSpeed, trackY, 0);
}
}
/// <summary>
/// Destroy the oldest symbol on the track
/// </summary>
void DestroyRightmostSymbol() {
activeWords.RemoveAt(0);
GameObject symbol = activeSymbols[0];
activeSymbols.RemoveAt(0);
Destroy(symbol);
}
/// <summary>
/// Find the chosen theme by its name
/// </summary>