Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0529134

Browse files
Added High Scores
added the saving of the highest score, lowest deaths and fastest time to the game, all of which can be seen in the level info screen via the level select
1 parent 694c413 commit 0529134

File tree

5 files changed

+2209
-38
lines changed

5 files changed

+2209
-38
lines changed

‎Native/Assets/Menus/EndScreen.cs

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class EndScreen : MonoBehaviour
2626
public inGameManager ingamemanager;
2727
public GameManager gameManager;
2828

29+
[Header("###########################")]
2930
[Header("Text Objects")]
3031
public TMP_Text kills;
3132
public TMP_Text shots;
@@ -34,6 +35,16 @@ public class EndScreen : MonoBehaviour
3435
public TMP_Text time;
3536
public TMP_Text score;
3637

38+
[Header("Best's")]
39+
public TMP_Text bestDeaths;
40+
public TMP_Text bestScore;
41+
public TMP_Text bestTime;
42+
43+
[Header("New Best Messages")]
44+
public GameObject deathsNewBest;
45+
public GameObject scoreNewBest;
46+
public GameObject timeNewBest;
47+
3748
public void OnEnable()
3849
{
3950
gameManager = GameObject.FindGameObjectWithTag("MANAGER").GetComponent<GameManager>();
@@ -42,15 +53,65 @@ public void OnEnable()
4253
Time.timeScale = 0f;
4354

4455
// initilse all of the UI componets of the end screen GUI
45-
kills.text = "Kills: " + gameManager.kills.ToString();
46-
shots.text = "shots: " + gameManager.shots.ToString();
47-
if (gameManager.shots == 0)
48-
accuracy.text = "accuracy: 100%";
56+
kills.text = gameManager.kills.ToString();
57+
shots.text = gameManager.shots.ToString();
58+
if (gameManager.shots == 0 || gameManager.kills == 0)
59+
accuracy.text = "0%";
60+
else
61+
accuracy.text = ((float)((float)gameManager.kills / (float)gameManager.shots) * 100f).ToString() + "%";
62+
death.text = gameManager.deaths.ToString();
63+
time.text = (gameManager.finishTime - gameManager.startTime).ToString();
64+
score.text = gameManager.score.ToString();
65+
66+
int savedLowestDeaths = PlayerPrefs.GetInt("LowestDeaths" + gameManager.currentSceneIndex, int.MaxValue);
67+
if (savedLowestDeaths == int.MaxValue)
68+
{
69+
PlayerPrefs.SetInt("LowestDeaths" + gameManager.currentSceneIndex, -1);
70+
savedLowestDeaths = PlayerPrefs.GetInt("LowestDeaths" + gameManager.currentSceneIndex, 0);
71+
}
72+
if (savedLowestDeaths < 0)
73+
bestDeaths.text = "N/A";
74+
else
75+
bestDeaths.text = savedLowestDeaths.ToString();
76+
77+
int savedHighestScore = PlayerPrefs.GetInt("HighestScore" + gameManager.currentSceneIndex, int.MaxValue);
78+
if (savedHighestScore == int.MaxValue)
79+
{
80+
PlayerPrefs.SetInt("HighestScore" + gameManager.currentSceneIndex, -1);
81+
savedHighestScore = PlayerPrefs.GetInt("HighestScore" + gameManager.currentSceneIndex, 0);
82+
}
83+
if (savedHighestScore < 0)
84+
bestScore.text = "N/A";
85+
else
86+
bestScore.text = savedHighestScore.ToString();
87+
88+
float savedFastestTime = PlayerPrefs.GetFloat("FastestTime" + gameManager.currentSceneIndex, float.MaxValue);
89+
if (savedFastestTime == float.MaxValue)
90+
{
91+
PlayerPrefs.SetFloat("FastestTime" + gameManager.currentSceneIndex, -1);
92+
savedFastestTime = PlayerPrefs.GetFloat("FastestTime" + gameManager.currentSceneIndex, 0);
93+
}
94+
if (savedFastestTime <= 0)
95+
bestTime.text = "N/A";
4996
else
50-
accuracy.text = "accuracy: " + ((gameManager.kills / gameManager.shots) * 100).ToString() + "%";
51-
death.text = "deaths: " + gameManager.deaths.ToString();
52-
time.text = "time: " + (gameManager.finishTime - gameManager.startTime).ToString();
53-
score.text = "score: " + gameManager.score.ToString();
97+
bestTime.text = savedFastestTime.ToString();
98+
99+
100+
if (gameManager.deaths < savedLowestDeaths || gameManager.deaths < 0)
101+
{
102+
PlayerPrefs.SetInt("LowestDeaths" + gameManager.currentSceneIndex, gameManager.deaths);
103+
deathsNewBest.SetActive(true);
104+
}
105+
if (gameManager.score > savedHighestScore)
106+
{
107+
PlayerPrefs.SetInt("HighestScore" + gameManager.currentSceneIndex, gameManager.score);
108+
scoreNewBest.SetActive(true);
109+
}
110+
if ((gameManager.finishTime - gameManager.startTime) < savedFastestTime || savedFastestTime <= 0)
111+
{
112+
PlayerPrefs.SetFloat("FastestTime" + gameManager.currentSceneIndex, (gameManager.finishTime - gameManager.startTime));
113+
timeNewBest.SetActive(true);
114+
}
54115
}
55116

56117
public void Update()

‎Native/Assets/Menus/MenuManager.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEngine.SceneManagement;
77
using TMPro;
88
using UnityEngine.InputSystem;
9+
using JetBrains.Annotations;
910

1011
public class MenuManager : MonoBehaviour
1112
{
@@ -233,8 +234,31 @@ public void inLevelInfoMenu()
233234
{
234235
// load all of the basic elements in (the level info)
235236
levelName.text = "Level " + (curLevel + 1).ToString();
236-
levelInfoText.text = "THIS IS A PLACE HOLDER FOR THE ACTUAL DESCRIPTION\n" + (curLevel + 1).ToString();
237237
//levelImage.sprite = Sprite;
238+
239+
int level = currentLevelSceneIndex[curLevel];
240+
241+
string deaths, score, time;
242+
int savedLowestDeaths = PlayerPrefs.GetInt("LowestDeaths" + level, int.MinValue);
243+
if (savedLowestDeaths < 0)
244+
deaths = "N/A";
245+
else
246+
deaths = savedLowestDeaths.ToString();
247+
248+
int savedHighestScore = PlayerPrefs.GetInt("HighestScore" + level, int.MinValue);
249+
if (savedHighestScore < 0)
250+
score = "N/A";
251+
else
252+
score = savedHighestScore.ToString();
253+
254+
float savedFastestTime = PlayerPrefs.GetFloat("FastestTime" + level, float.MinValue);
255+
if (savedFastestTime <= 0)
256+
time = "N/A";
257+
else
258+
time = savedFastestTime.ToString();
259+
260+
levelInfoText.text = "Lowest Deaths:\n" + deaths + "\nHighest Score:\n" + score + "\nFastest Time:\n" + time;
261+
238262
firstTime = false;
239263
}
240264
if (B.action.WasPressedThisFrame())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /