void Start() { dataController = FindObjectOfType <Data_Controller>(); // Store a reference to the DataController so we can request the data we need for this round currentRoundData = dataController.GetCurrentRoundData(); // Ask the DataController for the data for the current round. At the moment, we only have one round - but we could extend this questionPool = currentRoundData._questions; // Take a copy of the questions so we could shuffle the pool or drop questions from it without affecting the original RoundData object timeRemaining = currentRoundData._timeLimitInSeconds; // Set the time limit for this round based on the RoundData object UpdateTimeRemainingDisplay(); playerScore = 0; questionIndex = 0; ShowQuestion(); isRoundActive = true; }
private void HandleOnResponseReceived_Random(string response) { var fetchedData = new Opentdbcom_Class(); JsonUtility.FromJsonOverwrite(response, fetchedData); /* * var i = 0; * foreach (var result in randomData.results) { * Debug.Log("================" + i + "============="); * * Debug.Log("CATEGORY: " + result.category + "\n" + "type: " + result.type + "\n" + "difficulty: " + result.difficulty + "\n" + "question: " + result.question + "\n" + "correct_answer: " + result.correct_answer + "\n"); + + Debug.Log("INCORRECT_ANSWERS: \n"); + + foreach (var item in result.incorrect_answers) { + Debug.Log(item + "\n"); + } + + Debug.Log("======================================"); + + i++; + } */ var roundData = new Round_Data(); roundData._name = Menu_Controller.instance.urlCategory; roundData._pointsAddedForCorrectAnswer = 10; roundData._timeLimitInSeconds = Menu_Controller.instance.timeLimit; roundData._questions = new Question_Data[Menu_Controller.instance.urlNumberOfQuestions]; int k = 0; foreach (var result in fetchedData.results) { // (m+1) - number of answers int m = 0; foreach (var ans in result.incorrect_answers) { m++; } // questionText and answers[] initialization var question = new Question_Data(result.category, result.type, result.difficulty, result.question, m + 1); // answers[] filling int j = 0; foreach (var ans in result.incorrect_answers) { var qaj = question._answers[j]; qaj._answerText = ans; qaj._isCorrect = false; question._answers[j] = qaj; j++; } var qajPlus1 = question._answers[j]; qajPlus1._answerText = result.correct_answer; qajPlus1._isCorrect = true; question._answers[j] = qajPlus1; /* * //Debug.Log("QUESTION № " + roundData._questions.Length+1); * Debug.Log("BEFORE ORDER BY"); * Debug.Log("====================" + "\n"); * for (int i = 0; i < question._answers.Length; i++) { * Debug.Log(i + " : " + question._answers[i]._answerText + " - " + question._answers[i]._isCorrect + "\n"); * } * Debug.Log("====================" + "\n"); */ // Answer_Data[] answersWithRandomPos question._answers = question._answers.OrderBy(x => rnd.Next()).ToArray(); /* * Debug.Log("AFTER ORDER BY"); * Debug.Log("====================" + "\n"); * for (int i = 0; i < question._answers.Length; i++) { * Debug.Log(i + " : " + question._answers[i]._answerText + " - " + question._answers[i]._isCorrect + "\n"); * } * Debug.Log("====================" + "\n"); */ // QuestionData = questionText + answers[] roundData._questions[k] = question; k++; } /* * var i = 0; * foreach (var question in roundData._questions) { * Debug.Log("================" + i + "============="); * * Debug.Log("CATEGORY: " + question._category + "\n" + "type: " + question._type + "\n" + "difficulty: " + question._difficulty + "\n" + "question: " + question._questionText + "\n"); + + Debug.Log("ANSWERS: \n"); + + foreach (var item in question._answers) { + Debug.Log(item + "\n"); + } + + Debug.Log("======================================"); + + i++; + } */ allRoundData[0] = roundData; UnityEngine.SceneManagement.SceneManager.LoadScene("GameScene"); }