public void loadQuestion() { if (!PlayerPrefs.GetString("User", "").Equals("")) { FirebaseConnect.get("/questions/" + PlayerPrefs.GetString("User", ""), existing => { Dictionary <string, Question> entryDict = JsonConvert.DeserializeObject <Dictionary <string, Question> >(existing.ToString()); List <Question> entries = entryDict.Select(x => x.Value).ToList(); int randomnum = RandomNumber(0, entryDict.Count); questionID = entryDict.ElementAt(randomnum).Key; question = entryDict.ElementAt(randomnum).Value; questionText.text = String.Format( "You are eating {0} and you CGM reading is {1}." + Environment.NewLine + Environment.NewLine + "How much insulin should you take?", question.food, question.bloodsugar); options.Add(question.insulin); while (options.Count < 3) { double rand = RandomDouble(1, 6); if (!options.Contains(rand)) { options.Add(rand); } } options.Sort(); if (options[0] == 1) { option1.text = "1 Unit"; } else { option1.text = options[0] + " Units"; } if (options[1] == 1) { option2.text = "1 Unit"; } else { option2.text = options[1] + " Units"; } if (options[2] == 1) { option3.text = "1 Unit"; } else { option3.text = options[2] + " Units"; } timerLeft = 16.0f; loaded = true; Manage.Questionmenu(); }, error => { Manage.Againmenu(); }); } }
void OnTriggerEnter2D(Collider2D coll) { if (coll.gameObject.tag == "Hearth") { if (Manage.Sound == 0) { Hearthaudio.Play(); } Manage.Life += 1; if (Manage.Life >= 3) { Manage.Life = 3; } Items.Showitem(); Instantiate(Hearthparticle, new Vector3(coll.transform.position.x, coll.transform.position.y, transform.position.z), Quaternion.identity); Destroy(coll.gameObject); } if (coll.gameObject.tag == "End") { if (Manage.Sound == 0) { Playeraudio.Play(); } Manage.Life = 0; Manage.Lose = true; if (PlayerPrefs.GetString("User", "").Equals("")) { Manage.Againmenu(); } else { QuestionScreen.loadQuestion(); //Manage.Questionmenu(); } Items.Showitem(); Instantiate(feather[2], new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); Destroy(gameObject); //Manage.Questionmenu(); } if (coll.gameObject.tag == "Bird") { if (Oncejump == false) { Manage.InstantiateJump(); StartCoroutine(Newjump()); Manage.Jumpscore += 1; Oncejump = true; } if (transform.position.y < Cam.transform.position.y - 2) { Rgb2d.velocity = new Vector3(0, 20); } else if (transform.position.y >= Cam.transform.position.y - 2) { Rgb2d.velocity = new Vector3(0, 17); } Manage.Score += 10; Items.Showitem(); } if (coll.gameObject.tag == "Enemy") { if (Oncejump == false) { Manage.InstantiateJump(); StartCoroutine(Newjump()); Manage.Jumpscore += 1; Oncejump = true; } if (transform.position.y < Cam.transform.position.y - 2) { Rgb2d.velocity = new Vector3(0, 20); } else if (transform.position.y >= Cam.transform.position.y - 2) { Rgb2d.velocity = new Vector3(0, 17); } if (Damage == false) { Manage.Life -= 1; if (Manage.Sound == 0) { Playeraudio.Play(); } Instantiate(feather[0], new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); Items.Damageparticle(); if (Manage.Life <= 0) { Instantiate(feather[1], new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); Manage.Life = 0; Items.Showitem(); Manage.Lose = true; Manage.Againmenu(); Destroy(gameObject); } StartCoroutine(Newdamage()); Damage = true; } Items.Showitem(); } }