Skip to content
Snippets Groups Projects
Commit 043cb16c authored by mikeleo03's avatar mikeleo03
Browse files

feat : timer manager

parent e70b4389
1 merge request!1Main Menu, Timer, and Game Manager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
public void startGame() {
SceneManager.LoadScene(1);
}
private void Awake() {
DontDestroyOnLoad(gameObject);
}
}
fileFormatVersion: 2
guid: f885ef90267c9e34886fc0ff0361d2da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -7,6 +7,7 @@ namespace Nightmare ...@@ -7,6 +7,7 @@ namespace Nightmare
public class GameOverManager : MonoBehaviour public class GameOverManager : MonoBehaviour
{ {
private PlayerHealth playerHealth; private PlayerHealth playerHealth;
[SerializeField] private TimerManager timerManager;
Animator anim; Animator anim;
LevelManager lm; LevelManager lm;
...@@ -28,6 +29,7 @@ namespace Nightmare ...@@ -28,6 +29,7 @@ namespace Nightmare
void ShowGameOver() void ShowGameOver()
{ {
anim.SetBool("GameOver", true); anim.SetBool("GameOver", true);
timerManager.ResetTimer();
} }
private void ResetLevel() private void ResetLevel()
......
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class TimerManager : MonoBehaviour {
public Text Timer;
private double time = 0;
private bool isRunning = false;
private void Awake() {
StartTimer();
}
// Update is called once per frame
void Update() {
if (isRunning) {
time = time + Time.deltaTime;
}
string timeText = System.TimeSpan.FromSeconds(time).ToString("mm':'ss");
Timer.text = timeText;
}
public void ResetTimer() {
time = 0;
}
public double TakeTime() {
StopTimer();
var r = time;
ResetTimer();
return r;
}
public void StartTimer() {
isRunning = true;
}
public void StopTimer() {
isRunning = false;
}
}
fileFormatVersion: 2
guid: ba9cb599a6b30804b9567e87aa4422e7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -5,6 +5,9 @@ EditorBuildSettings: ...@@ -5,6 +5,9 @@ EditorBuildSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 2 serializedVersion: 2
m_Scenes: m_Scenes:
- enabled: 1
path: Assets/Scenes/Menu.unity
guid: 36e3c5cd16db60e40bb73a4facc7eecd
- enabled: 1 - enabled: 1
path: Assets/Scenes/Main.unity path: Assets/Scenes/Main.unity
guid: 11930b577543f644eb2aed6e2001fd38 guid: 11930b577543f644eb2aed6e2001fd38
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment