@@ -26,6 +26,7 @@ public class EndScreen : MonoBehaviour
26
26
public inGameManager ingamemanager ;
27
27
public GameManager gameManager ;
28
28
29
+ [ Header ( "###########################" ) ]
29
30
[ Header ( "Text Objects" ) ]
30
31
public TMP_Text kills ;
31
32
public TMP_Text shots ;
@@ -34,6 +35,16 @@ public class EndScreen : MonoBehaviour
34
35
public TMP_Text time ;
35
36
public TMP_Text score ;
36
37
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
+
37
48
public void OnEnable ( )
38
49
{
39
50
gameManager = GameObject . FindGameObjectWithTag ( "MANAGER" ) . GetComponent < GameManager > ( ) ;
@@ -42,15 +53,65 @@ public void OnEnable()
42
53
Time . timeScale = 0f ;
43
54
44
55
// 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" ;
49
96
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
+ }
54
115
}
55
116
56
117
public void Update ( )
0 commit comments