Skip to content

Commit d8a258a

Browse files
committed
Now you can visualize the score, and you can also restart or quit the game
1 parent 7f05a5e commit d8a258a

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

Assets/Source/Canvas/ScoreView.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
4+
public class ScoreView : MonoBehaviour
5+
{
6+
public Text score;
7+
8+
public void SetScore(int score)
9+
{
10+
this.score.text = score.ToString();
11+
}
12+
}

Assets/Source/Canvas/ScoreView.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Source/GameManager.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
4+
using UnityEngine.SceneManagement;
45

56
public class GameManager : MonoBehaviour {
67

78
public TimerView timerView;
9+
public ScoreView scoreView;
10+
public GameObject endgameView;
11+
812
public SpawnFlag spawner;
913

14+
string player = "Player1";
15+
16+
string thisScenePath = "Scene/testScene";
17+
1018
public float time;
1119

1220
bool gameOver;
@@ -34,6 +42,17 @@ void Update ()
3442
{
3543
UpdateTimer();
3644
}
45+
else
46+
{
47+
if(Input.GetKey(KeyCode.Return))
48+
{
49+
ResetGame();
50+
}
51+
if(Input.GetKey(KeyCode.Q))
52+
{
53+
Application.Quit();
54+
}
55+
}
3756
}
3857

3958
void UpdateTimer()
@@ -52,7 +71,11 @@ void UpdateTimer()
5271

5372
public void FlagTaken(string player)
5473
{
55-
player2Score[player] += 1;
74+
player2Score[player] += 1;
75+
76+
if (player == this.player)
77+
scoreView.SetScore(player2Score[player]);
78+
5679
spawner.SpawnNextFlag();
5780
}
5881

@@ -63,10 +86,12 @@ void EndGame()
6386
Time.timeScale = 0;
6487

6588
// Show a message when you win with the total points
89+
endgameView.SetActive(true);
6690
}
6791

6892
void ResetGame()
6993
{
7094
// Fai un restart della scena
71-
}
95+
SceneManager.LoadScene(thisScenePath, LoadSceneMode.Single);
96+
}
7297
}

0 commit comments

Comments
 (0)