Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

Commit 16ebafc

Browse files
committed
Added Win Menu and fixed restarting more than one time
1 parent 8fa922f commit 16ebafc

7 files changed

Lines changed: 1678 additions & 139 deletions

File tree

Assets/Scripts/DeadMenu.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66

77
public class DeadMenu : MonoBehaviour {
88

9-
Button restart, options, exit, exitOptions;
9+
public Button restart, options, exit, exitOptions;
1010

1111

1212
public OptMenu optMenu;
1313

1414
void Start() {
15-
restart = GameObject.FindWithTag("Restart").GetComponent<Button>();
1615
restart.onClick.AddListener(RestartGame);
17-
18-
options = GameObject.FindWithTag("Options").GetComponent<Button>();
19-
options.onClick.AddListener(OptionsMenu);
20-
21-
exit = GameObject.FindWithTag("Exit").GetComponent<Button>();
22-
2316

17+
options.onClick.AddListener(OptionsMenu);
2418
}
2519

2620
//Restart Method

Assets/Scripts/Key.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class Key : MonoBehaviour {
66

77
public GameObject[] ignoreCollisions;
88

9+
public GameObject WinMenu;
10+
911
GameObjectPool keyPool;
1012

1113
private void Start() {
@@ -23,7 +25,8 @@ void OnCollisionEnter2D(Collision2D collision) {
2325
keyPool.AddGameObject(gameObject);
2426

2527
if(Variables.keysObtained == 8) {
26-
28+
WinMenu.SetActive(true);
29+
Time.timeScale = 0;
2730
}
2831
}
2932
}

Assets/Scripts/TimeUI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
public class TimeUI : MonoBehaviour {
77

8+
public float timeInSeconds;
9+
810
Text text;
9-
float timeInSeconds;
1011
Cam mainCamera;
1112
// Use this for initialization
1213
void Start () {

Assets/Scripts/WinMenu.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEngine.UI;
5+
using UnityEngine.SceneManagement;
6+
7+
public class WinMenu : MonoBehaviour {
8+
9+
public Text TimeScore, GameScore, FinalScore, TimeUI;
10+
11+
public Button restart, options, exit;
12+
13+
public OptMenu optMenu;
14+
15+
int placeHolder;
16+
17+
float TS, GS, FS;
18+
19+
// Use this for initialization
20+
void Start() {
21+
restart.onClick.AddListener(RestartGame);
22+
23+
options.onClick.AddListener(OptionsMenu);
24+
25+
gameObject.SetActive(false);
26+
}
27+
28+
// Update is called once per frame
29+
void Update() {
30+
//Calculate Timescore
31+
placeHolder = int.Parse(TimeScore.text);
32+
if(placeHolder >= 60) {
33+
TimeScore.text = 60.ToString();
34+
TS = 60;
35+
} else {
36+
TimeScore.text = (1000f / placeHolder).ToString();
37+
TS = 1000f / placeHolder;
38+
}
39+
//Set GameScore
40+
GameScore.text = Variables.score.ToString();
41+
GS = Variables.score;
42+
//Set FinalScore
43+
FS = TS + GS;
44+
FinalScore.text = FS.ToString();
45+
}
46+
47+
void RestartGame() {
48+
Variables.score = 0;
49+
Variables.keysObtained = 0;
50+
Time.timeScale = 1;
51+
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
52+
}
53+
54+
void OptionsMenu() {
55+
optMenu.gameObject.SetActive(true);
56+
}
57+
}

Assets/Scripts/WinMenu.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)