RoadRunner/Assets/script/ObjectIdentification.cs
2025-01-30 23:38:06 +01:00

174 lines
5.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class ObjectIdentification : 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()
{
arrow.fontSize = 290;
arrow.color = Color.yellow;
questionmark.fontSize = 290;
questionmark.color = Color.yellow;
GameObject objectOfInteraction = transform.GetChild(0).gameObject;
outline = objectOfInteraction.AddComponent<Outline>();
outline.OutlineColor = Color.yellow;
outline.OutlineWidth = 5f;
outline.OutlineMode = Outline.Mode.OutlineAll;
outline.enabled = false;
canvasObject = GameObject.Find("Canvas").transform;
player = Camera.main.transform;
if (isCorrectA){
correctOption = "a";
}
else if(isCorrectB)
{
correctOption = "b";
}
goaltimer = transform.parent.Find("goalmanager").GetComponent<goalTimer>();
//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 onHover()
{
debug.GetComponent<TextMeshProUGUI>().text = "<font=\"Urbscape SDF\"><mark=#00000>" + "hover" + "</mark>";
if (selected == false){
arrow.fontSize = 250;
arrow.color = Color.yellow;
questionmark.fontSize = 250;
questionmark.color = Color.yellow;
outline.enabled = true;
outline.OutlineWidth = 6f;
}
}
public void onHoverExit()
{
debug.GetComponent<TextMeshProUGUI>().text = "<font=\"Urbscape SDF\"><mark=#00000>" + "hover exit" + "</mark>";
if (selected == false){
arrow.fontSize = 200;
arrow.color = Color.yellow;
questionmark.fontSize = 200;
questionmark.color = Color.yellow;
outline.enabled = false;
outline.OutlineWidth = 5f;
}
}
public void selectUnselected()
{
debug.GetComponent<TextMeshProUGUI>().text = "<font=\"Urbscape SDF\"><mark=#00000>" + "selected" + "</mark>";
if (selected == false)
{
outline.OutlineWidth = 5f;
arrow.fontSize = 0;
questionmark.fontSize = 0;
outline.OutlineColor = Color.white;
selected = true;
Debug.Log("options = true");
options.SetActive(true);
Debug.Log(options);
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);
//yield return null;
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)
{
Debug.Log(goaltimer);
options.SetActive(true);
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);
}
}
}