using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = “New Quiz”, menuName = “Quiz Question”, order = 0)]
public class QuestionSO : ScriptableObject {
[TextArea (4 ,6)]
[SerializeField] string question = "Enter The Quiz";
[SerializeField] string[] answers = new string[4];
[SerializeField] int correctAnswerIndex;
public string getQuestion()
{
return question;
}
public string getanswer(int index)
{
return answers[index];
}
public int getCorrectAnswerIndex()
{
return correctAnswerIndex;
}
}
==============================================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class Quiz : MonoBehaviour
{
[SerializeField]TextMeshProUGUI questionText;
[SerializeField]QuestionSO question;
[SerializeField] GameObject[] answerButtons;
int correctAnswerIndex;
[SerializeField] Sprite defaultAnswerSprite;
[SerializeField] Sprite correctAnswerSprite;
void Start()
{
questionText.text = question.getQuestion();
for (int i = 0; i< answerButtons.Length; i++)
{
TextMeshProUGUI buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();buttonText.text = question.getanswer(i);
}
}
public void OnAnswerSelected(int index)
{
if (index == question.getCorrectAnswerIndex())
{
questionText.text = "BENARRR!!";
Image buttonImage = answerButtons[index].GetComponent<Image>();
buttonImage.sprite = correctAnswerSprite;
}
}
}