UNITY c#:是否可以将 True 和 False 按钮​​更改为 4 个不同的按钮选择并仍然使用 "public bool"?

UNITY c#:is it possible to change True and False button to 4 different button choices and still using "public bool"?

我做了一个测验,但只有真和假的按钮,

从 brackeys 教程中得到它们

如何将它们变成具有 4 个不同选择的 4 个按钮。

统一分配给按钮对象

这是我的真假代码(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;


 }

如果您正在寻找一种方法让每个问题都有多个答案,但其行为类似于布尔值,那么您可能正在寻找这样的东西:

enum Response { yes, no, maybe, dontknow }
public Response answerToQ1;

将其添加到您的代码中,然后在检查器中查看,它用作下拉菜单。

比较其当前状态:

if (answerToQ1 == Response.yes)
    //correct
else 
    //incorrect

switch (answerToQ1) {
    case Response.yes:
        //correct
        break;
    case Response.no:
        //incorrect
        break;
}