RoadRunner/Assets/Choise.cs
2025-01-29 22:55:46 +01:00

129 lines
3.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class Choise : MonoBehaviour, OptionLogic
{
public bool selected = false;
public string titleString;
public GameObject options;
public string optionAText;
public bool isCorrectA;
public string optionBText;
public bool isCorrectB;
private string correctOption;
private goalTimer goaltimer;
public TextMeshProUGUI arrow;
public TextMeshProUGUI questionmark;
Outline outline;
private Transform canvasObject;
private Transform player;
public GameObject debug;
public GameObject goalManager;
// Start is called before the first frame update
void Start()
{
//canvasObject = GameObject.Find("Canvas").transform;
player = Camera.main.transform;
if (isCorrectA){
correctOption = "a";
}
else if(isCorrectB)
{
correctOption = "b";
}
goaltimer = goalManager.GetComponent<goalTimer>();
selectUnselected();
//StartCoroutine(waiter());
}
IEnumerator waiter()
{
//Wait for 4 seconds
yield return new WaitForSecondsRealtime(4);
Debug.Log("selectUnselected");
selectUnselected();
}
// Update is called once per frame
void Update()
{
//canvasObject.LookAt(player);
}
public void selectUnselected()
{
if (selected == false)
{
selected = true;
options.SetActive(true);
options.transform.Find("title").GetComponentInChildren<TextMeshProUGUI>().text = "<font=\"Urbscape SDF\"><mark=#00000>" + titleString + "</mark>";
GameObject optionA = options.transform.Find("a").gameObject;
TextMeshProUGUI optionAtextObject = optionA.transform.GetChild(0).gameObject.GetComponentInChildren<TextMeshProUGUI>();
optionAtextObject.text = optionAText;
optionA.GetComponent<Button>().onClick.RemoveAllListeners();
optionA.GetComponent<Button>().onClick.AddListener(() => optionSelected("a"));
GameObject optionB = options.transform.Find("b").gameObject;
TextMeshProUGUI optionBtextObject = optionB.transform.GetChild(0).gameObject.GetComponentInChildren<TextMeshProUGUI>();
optionBtextObject.text = optionBText;
optionB.GetComponent<Button>().onClick.RemoveAllListeners();
optionB.GetComponent<Button>().onClick.AddListener(() => optionSelected("b"));
options.GetComponentInChildren<optionClicked>().SetLevel(this);
StartCoroutine(options.GetComponentInChildren<optionClicked>().StartOptionChoise(optionSelected));
// change option text and where the functions point to!
// Bring up a selection of categories -> other buttons that then have logic and impacts game status.
}
}
public void optionSelected(string option)
{
selected = false;
options.SetActive(false);
if (option == "timeout"){
return;
}
if (option == correctOption)
{
debug.GetComponent<TextMeshProUGUI>().text = "<font=\"Urbscape SDF\"><mark=#00000>" + "Done correct: " +option+ "</mark>";
Debug.Log("option true");
goaltimer.OptionSelection(true);
}
else
{
Debug.Log("option false");
debug.GetComponent<TextMeshProUGUI>().text = "<font=\"Urbscape SDF\"><mark=#00000>" + "Done incorrect: " +option+ "</mark>";
goaltimer.OptionSelection(false);
}
}
}