So when I run the game and enter the answer, nothing happens, the input field just clears itself
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static List<(string question, string answer)> availQuest;
private string crntQ;
private string crntA;
void Start()
{
InitializeQuestions();
Randomize();
}
public void InitializeQuestions()
{
availQuest = new List<(string, string)> {
("3 - 2", "1"), // Answer is 1
("2 x 4", "8"), // Answer is 8
("50 - 30", "20"), // Answer is 9.5
("0 x 0", "0"), // Answer is -16
("5 + 5 - 3", "7"), // Answer is 7
("10 x 5", "50"), // Answer is 72
("6(2) - 2", "10"), // Answer is 27
("5 + 5", "10"), // Answer is 10
("10 / 2", "5"), // Answer is 9
("2 + 2", "4") // Answer is 4
};
}
public void Randomize()
{
if (availQuest.Count > 0)
{
int rnd = Random.Range(0, availQuest.Count);
crntQ = availQuest[rnd].question;
crntA = availQuest[rnd].answer;
availQuest.RemoveAt(rnd);
}
}
public string CurrentQ()
{
return crntQ;
}
public string CurrentA()
{
return crntA;
}
using System;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Collections.Generic;
public class InputHandler : MonoBehaviour
{
[SerializeField] InputField inputField;
[SerializeField] Text textResult;
private GameManager gm;
private Queue<GameManager> enemyQ = new Queue <GameManager>();
void Start()
{
}
void Update()
{
if (inputField.isFocused && (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)))
{
InputVal();
}
}
public void AddQ(GameManager enemy)
{
enemyQ.Enqueue(enemy);
}
public void InputVal()
{
string input = inputField.text.Trim();
if (enemyQ.Count > 0)
{
GameManager crntE = enemyQ.Peek();
if (input.Equals(crntE.CurrentA().Trim(), StringComparison.InvariantCultureIgnoreCase))
{
textResult.text = "CORRECT!";
textResult.color = Color.yellow;
Debug.Log("Correct Answer: " +crntE.CurrentA());
Destroy(crntE.gameObject);
enemyQ.Dequeue();
if (enemyQ.Count > 0)
{
enemyQ.Peek().Randomize();
}
}
else
{
textResult.text = "INCORRECT!";
textResult.color = Color.red;
Debug.Log("Correct Answer: " +crntE.CurrentA());
}
}
inputField.text = string.Empty;
inputField.ActivateInputField();
}