public override void LoadContent() { if (!ContentLoaded) { if (currentLoadingStep <= totalLoadingSteps) { switch (currentLoadingStep) { case 0: QuestionsDatabase.LoadQuestions(); break; case 1: bg.Load(parent.Content); break; case 2: player.Load(parent.Content); break; case 3: ball.Load(parent.Content); break; case 4: field.Load(parent.Content); break; case 5: LoadUI(); break; } currentLoadingStep++; } else { shouldReset = true; contentLoaded = true; } } }
// Use this for initialization void Start() { database = gameObject.GetComponent <QuestionsDatabase>(); aDatabase = gameObject.GetComponent <AchievementsDatabase>(); allocButton = new List <Button>(); allocAnswer = new bool[4]; allocated = new bool[4]; answerText = new string[4]; System.Random srand = new System.Random(); int rand = 0; int correctAnswer = srand.Next(1, 4); // change this Question question = database.FetchQuestionByID(DataManager.animalClicked); answerText[0] = question.answer1; answerText[1] = question.answer2; answerText[2] = question.answer3; answerText[3] = question.answer4; while (allocButton.Count != 4) { rand = srand.Next(0, 4); if (!allocated[rand] && !allocAnswer[rand]) { buttons[rand].transform.GetChild(0).GetComponent <Text>().text = answerText[rand]; if (rand == correctAnswer - 1) { buttons[rand].onClick.AddListener(() => { PlayerPrefs.SetInt("goldcoins", PlayerPrefs.GetInt("goldcoins") + 5); PlayerPrefs.SetInt("answeredQuestion", PlayerPrefs.GetInt("answeredQuestion") + 1); // Check if achieved something Achievement answeredAchievement = aDatabase.FetchAchievementByName("Answer 3 Questions"); // Get user Achievements bool[] userAchievements = PlayerPrefsX.GetBoolArray("userAchievements"); if (userAchievements.Length == 0) { userAchievements = new bool[aDatabase.getCount()]; } if (answeredAchievement.requirement <= PlayerPrefs.GetInt("answeredQuestion") && !userAchievements[answeredAchievement.id]) { PlayerPrefs.SetInt("goldcoins", PlayerPrefs.GetInt("goldcoins") + answeredAchievement.reward_gold); PlayerPrefs.SetInt("exp", PlayerPrefs.GetInt("exp") + answeredAchievement.reward_exp); achieved = true; // Copy Achievements and save new bool[] dummy = new bool[aDatabase.getCount()]; for (int i = 0; i < userAchievements.Length; i++) { dummy[i] = userAchievements[i]; } dummy[answeredAchievement.id] = true; PlayerPrefsX.SetBoolArray("userAchievements", dummy); } // Save PlayerPrefs.Save(); rewardSound.Play(); correctPanel.SetActive(true); }); } else { buttons[rand].onClick.AddListener(() => { wrongPanel.SetActive(true); wrongSound.Play(); }); } allocButton.Add(buttons[rand]); allocated[rand] = true; allocAnswer[rand] = true; } } correctPanel.transform.GetChild(1).GetComponent <Button>().onClick.AddListener(() => { if (achieved) { correctPanel.SetActive(false); achievedPanel.SetActive(true); rewardSound.Play(); } else { GameObject.Find("SceneManager").GetComponent <ScreenManager>().returnToMenu(); } }); achievedPanel.transform.GetChild(1).GetComponent <Button>().onClick.AddListener(() => { GameObject.Find("SceneManager").GetComponent <ScreenManager>().returnToMenu(); }); wrongPanel.transform.GetChild(1).GetComponent <Button>().onClick.AddListener(() => { GameObject.Find("SceneManager").GetComponent <ScreenManager>().returnToMenu(); }); questionImage.GetComponent <Image>().sprite = Resources.Load <Sprite>("Sprite/AnimalInfoImage/" + question.animal_name + "/" + correctAnswer); }