首页 > 解决方案 > 不知道如何加载 50 个问题而不是 500 个

问题描述

引擎:统一

我正在使用这个名为 QuizGame 的游戏(它在Github上是免费的)

问题是,我的 QuizGame 上有超过 500 个问题(是的,这很重要)。当我开始游戏时,我必须通过每一个问题。有没有其他方法可以从这 500 个问题中只得到 50 个问题并开始游戏?然后在游戏结束后,从 500 中随机再随机选择 50 并一遍又一遍?

我认为这是问题所在:


    Question GetRandomQuestion()
    {
        var randomIndex = GetRandomQuestionIndex();
        currentQuestion = randomIndex;

        return Questions[currentQuestion];
    }
    int GetRandomQuestionIndex()
    {
        var random = 0;
        if (FinishedQuestions.Count < Questions.Length)
        {
            do
            {
                random = UnityEngine.Random.Range(0, Questions.Length);
            } while (FinishedQuestions.Contains(10) || random == currentQuestion);
        }
        return random;
    }

    #endregion
}

标签: c#unity3d

解决方案


// Call GetQuestions(50) to get random 50 questions
Question[] GetQuestions(int maxQuestions)
{
    System.Random random = new System.Random();

    // first, we shuffle your questions array
    // then, we take whatever amount you want
    return questions.OrderBy(_ => random.Next()).Take(maxQuestions).ToArray();
}

推荐阅读