I made a quiz but true and false are the only buttons,
Got them from a tutorial which is brackeys
how do I make them to 4 buttons with 4 different choices.
and assign them to button objects in unity
here are my codes for true and false(GameManager.cs)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class GameManager : MonoBehaviour
{
public Question[] questions;
private static List<Question> unansweredQuestions;
private Question currentQuestion;
[SerializeField]
private Text factText;
void Start()
{
if (unansweredQuestions == null || unansweredQuestions.Count == 0)
{
unansweredQuestions = questions.ToList<Question>();
}
SetCurrentQuestion();
}
void SetCurrentQuestion()
{
int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
currentQuestion = unansweredQuestions[randomQuestionIndex];
factText.text = currentQuestion.fact;
unansweredQuestions.RemoveAt(randomQuestionIndex);
}
public void UserSelectTrue()
{
if (currentQuestion.isTrue)
{
Debug.Log("CORRECT");
} else
{
Debug.Log("WRONG");
}
public void UserSelectFalse()
{
if (!currentQuestion.isTrue)
{
Debug.Log("CORRECT");
} else
{
Debug.Log("WRONG");
}
}
Question.cs
[System.Serializable]
public class Question {
public string fact;
public bool isTrue;
}
If you're looking for a way for each question to have more than one answer but act similar to a bool then you are probably looking for something like this:
enum Response { yes, no, maybe, dontknow }
public Response answerToQ1;
Add that to your code, then look in the inspector, it works as a dropdown menu.
To compare its current state:
if (answerToQ1 == Response.yes)
//correct
else
//incorrect
or
switch (answerToQ1) {
case Response.yes:
//correct
break;
case Response.no:
//incorrect
break;
}