Проблема с массивом для приложения викторины с разными предметами - PullRequest
0 голосов
/ 03 апреля 2019

Я нашел ошибку для моего приложения для игры в викторину, но я не знаю, что ее вызвало или как ее исправить. Все вопросы и варианты собраны внутри массива, и как только сцена начинается, сценарий работает.

все работает просто отлично, вопросы и выбор появляются так, как и должны.

что я хочу сделать, это исправить эту ошибку, которая у меня есть, но я не знаю, с чего начать, и мне нужна помощь

так как я пытаюсь выяснить, что происходит, и не могу понять, почему это происходит, я попытался переделать весь сценарий и попытался воссоздать то же самое или что-то подобное от начала до конца, и я все еще получил то же самое результат. ИДК, может быть, я просто неправильно подхожу

[System.Serializable]
public class Questions 
{
    public string question;
    public string answer;
}

Менеджер

public class Manager : MonoBehaviour
{
    /*Calls Questions.cs
     *Creates an array and calls it [questions]
     *Creates a List and calls it [unansweredQuestions] with the format of
     *Questions.cs
     *Creates a private variable and calls it [currentQuestion]
     */
    public Questions[] questions; 
    public static List<Questions> unansweredQuestions;
    public static Questions currentQuestion;

    [SerializeField]
    public Text questionText;
    //gameObject
    public Text firstChoiceanswer;
    public Text secondChoiceanswer;
    //gameObject's text
    public Text A1;
    public Text A2;


    [SerializeField]
    public float TimeBetweenQuestions = 1f;
    //waits a few seconds

    void Start()
    {
        if (unansweredQuestions == null || unansweredQuestions.Count == 0)
        {
            unansweredQuestions = questions.ToList<Questions>();   
        }
        SetCurrentQuestion();
    }

    void SetCurrentQuestion()
    {
        int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
        currentQuestion = unansweredQuestions[randomQuestionIndex];

        //Random position where the choices will go buttons
        int randomAnswerIndex = Random.Range(0, 2);

        if(randomAnswerIndex == 0)
        {
            A1.text = currentQuestion.answer;
            A2.text = currentQuestion.wronganswer;
        } else if (randomAnswerIndex == 1)
        {
            A2.text = currentQuestion.answer;
            A1.text = currentQuestion.wronganswer;
        }
        //changes the text with a random question
        questionText.text = currentQuestion.question;
    }

    //Checks the answer in A1
    public void AnswerChecking1()
    {
        if (currentQuestion.answer == firstChoiceanswer.text)
        {
            Debug.Log("Correct");
        }
        else
        {
            Debug.Log("Wrong");
        }
        WaitTransitionToNextQuestion();
        LoadNextQuestion();
    }

    //Checks the answer in A2
    public void AnswerChecking2()
    {
        if (currentQuestion.answer == secondChoiceanswer.text)
        {
            Debug.Log("Correct");
        }
        else
        {
            Debug.Log("Wrong");
        }
        WaitTransitionToNextQuestion();
        LoadNextQuestion();
    }

    //waits for abit to change question
    IEnumerator WaitTransitionToNextQuestion()
    {
        yield return new WaitForSeconds(TimeBetweenQuestions);
    }

    //Changes the Question after answered
    public void LoadNextQuestion()
    {
        SetCurrentQuestion();
    }
}

Меню содержит как минимум 4 различных объекта, пользователь должен выбрать один из этих 4, а затем перенести пользователя в другую сцену для этого объекта.

Эта проблема возникает всякий раз, когда я запускаю новую игру и выбираю предмет (например, по математике), всякий раз, когда я возвращаюсь к выбору предмета и щелкаю по другому предмету (например, на английском), вместо того, чтобы показывать новые вопросы и варианты, вопросы и варианты выбора предыдущей темы (первой темы) по-прежнему отображаются вместо новой выбранной темы, и я не знаю, почему она это делает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...