private void CreateHighscoreEntry(HighscoreEntry entry, Transform container, List <Transform> transformList) { Transform entryTransform = Instantiate(entryTemplate, container); RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>(); entryRectTransform.anchoredPosition = new Vector2(0, -templateHeight * transformList.Count); entryTransform.gameObject.SetActive(true); // Rank int rank = transformList.Count + 1; string rankString = Highscores.AddOrdinal(rank); entryTransform.Find("positionText").GetComponent <Text>().text = rankString; // Score int score = entry.score; entryTransform.Find("scoreText").GetComponent <Text>().text = score.ToString(); // Name string name = entry.name; entryTransform.Find("nameText").GetComponent <Text>().text = name; entryTransform.Find("entryBackground").gameObject.SetActive(rank % 2 == 1); transformList.Add(entryTransform); }
void Update() { if (Input.GetButtonDown("Pickup")) { if (field == fields.Return) // If the score tally has been finished { // Return to the menu, but only if the highscore prompt is not open if (!highscorePrompt.gameObject.activeInHierarchy) { GameManager.instance.ReturnToMenu(); } } else // Skip the tally { skipped = true; timer = duration + 1; } } // Increment timer for score tallying timer += Time.deltaTime; if (timer > duration) { // Set text fields active // There are two switch statements for the same condition because // these cases execute at the end of the timer, while the other ones // need to execute throughout the timer. switch (field) { case fields.Condition: // Completion Condition and Reason if (GameManager.isVictory) { // Debug.Log("YOU WON!"); completionCondtionText.text = "Victory"; completionReasonText.text = "You got to the 'choppa"; } else { // Debug.Log("YOU LOST!"); completionCondtionText.text = "Defeat"; completionReasonText.text = "You were devoured by moles"; } ActivateField(completionCondtionText); break; case fields.Reason: ActivateField(completionReasonText); break; case fields.Score: ActivateField(scoreText); break; case fields.Wait: // Adds a delay between score showing up and the tally starting duration = 1.5f; break; case fields.Return: // ActivateField(returnText); duration = 0f; if (!returnText.gameObject.activeInHierarchy) { returnText.gameObject.SetActive(true); audio.clip = returnSound; audio.Play(); Cursor.lockState = CursorLockMode.None; // If score is a highscore, prompt for name and save score if (isHighScore) { // Cursor.visible = false; highscorePrompt.gameObject.SetActive(true); highscorePrompt.score = score; highscorePrompt.pos = rank; } } break; } // Reset timer unless skipped if (!skipped) { timer = 0; } if (field != fields.Return) { field++; // Move on to the next field when this one is finished } } // Tally the current field switch (field) { case fields.Waves: // Waves TallyField(WaveSpawner.nextWave, wavesText, "Waves Survived: ", GameStats.WAVE_SCORE); break; case fields.ChildrenSaved: // Children Saved TallyField(GameStats.childrenSaved, childrenSavedText, "Children Saved: ", GameStats.CHILD_SCORE); break; case fields.Kills: // Kills TallyField(GameManager.kills, killsText, "Kills: ", GameStats.KILL_SCORE); break; case fields.Damage: // Damage TallyField(GameManager.damage, damageText, "Damage Dealt: ", 1f); // score += scoreTally; duration = .25f; break; case fields.HighScore: // HighScore HighscoreList list = Highscores.LoadScores(); if (!HighScoreText.gameObject.activeInHierarchy) { // print(score); score += scoreTally; // print (score); int pos = Highscores.CheckScore(score, list.scoreList); // int pos = Highscores.CheckScore(50001, list.scoreList); if (pos != -1 && pos != 10) { // You made it to the highscore list! // Highscores.AddScore(pos, entry, highscores); isHighScore = true; rank = pos; // Play sound audio.clip = textSound; audio.Play(); // Display message if (pos == 0) { // You got 1st place! HighScoreText.text = "You got 1st place!\n" + "You were ahead by " + list.scoreList[pos + 1].score + "points!"; } else { HighScoreText.text = "You got " + Highscores.AddOrdinal(pos + 1) + " place!\n" + "The next highest score is " + list.scoreList[pos].score + "."; } // Set highscore text fields to active NewText.gameObject.SetActive(true); HighScoreText.gameObject.SetActive(true); } else { // Better luck next time. print("Score " + score + " too low. You didn't make the cut."); } } // if ((score + scoreTally) > PlayerPrefs.GetInt("HighScore")) // { // PlayerPrefs.SetInt("HighScore", (score + scoreTally)); // NewText.gameObject.SetActive(true); // } // TallyField(PlayerPrefs.GetInt("HighScore"), HighScoreText, "HighScore: ", 0); break; } }