using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; public class QuestionHandler : MonoBehaviour { public GameObject managers; private GameManager gameManager; public TextMeshProUGUI explainText; public PromptList promptList; private List player2questions; private int currentQuestion = 0; void OnEnable() { player2questions = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer); Redraw(++currentQuestion); } void OnDisable() { player2questions = null; } void Redraw(int currentQuestion) { Prompt prompt = promptList.prompts.Find(x => x.id == player2questions[currentQuestion - 1].promptId); explainText.SetText(prompt.en); CameraManager cameraManager = gameObject.GetComponent(); cameraManager.WebcamResume(); } string GetQuestionRef(string promptId) { return gameManager.myRoom.questions.First(x => x.Value.promptId == promptId).Key; } string GetPropRef(string questionRef, string playerId) { return gameManager.myRoom.questions[questionRef].propositions.First(x => x.Value.owner.id == playerId).Key; } public void OnSubmitButton() { string questionRef = GetQuestionRef(player2questions[currentQuestion - 1].promptId); StorageManager storageManager = managers.GetComponent(); storageManager.UploadPhoto( gameManager.myRoom.code, gameManager.currentPlayer.id, GetQuestionRef(questionRef), GetPropRef(questionRef, gameManager.currentPlayer.id)); if (currentQuestion < 2) { Redraw(++currentQuestion); } else { gameManager.myRoom.currentState = (int) GameState.PropositionsSent; } } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } }