OXManager.cs 소스입니다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class Question
{
public string question;
public bool isO;
}
public class OXManager : MonoBehaviour
{
[SerializeField] Question[] questions;
Question question;
[SerializeField] Text questionText;
[SerializeField] Text resultText;
[SerializeField] Text correctText;
[SerializeField] GameObject confirmParticle;
[SerializeField] int level;
int Level
{
get => level;
set
{
level = value;
ShowQuestion(value);
}
}
[SerializeField] int correctCount;
int CorrectCount
{
get => correctCount;
set
{
correctCount = value;
correctText.text = $"맞춘개수 : {value}";
}
}
public void ShowQuestion(int level)
{
if (level >= questions.Length)
return;
question = questions[level];
questionText.text = question.question;
}
public void AnswerClick(bool isO)
{
if (question.isO == isO)
{
StartCoroutine(ResultCo("정답"));
confirmParticle.SetActive(true);
Level++;
CorrectCount++;
}
else
{
StartCoroutine(ResultCo("틀림"));
Level++;
}
}
void Start()
{
ShowQuestion(Level);
}
IEnumerator ResultCo(string text)
{
resultText.text = text;
yield return new WaitForSeconds(2);
resultText.text = "";
}
}