90 lines
2.0 KiB
C#
90 lines
2.0 KiB
C#
using SHADE;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public class GameManager : Script
|
|
{
|
|
public enum GameState
|
|
{
|
|
START,
|
|
WIN,
|
|
LOSE
|
|
}
|
|
|
|
public uint winScene = 92009475;
|
|
public uint loseScene = 91685359;
|
|
|
|
[NonSerialized]
|
|
public GameState currGameState;
|
|
[NonSerialized]
|
|
public int totalItemCount;
|
|
[NonSerialized]
|
|
public int Score;
|
|
[NonSerialized]
|
|
public float timer;
|
|
|
|
public GameObject scoreText;
|
|
public GameObject timeText;
|
|
|
|
public static GameManager Instance { get; private set; }
|
|
|
|
protected override void awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
RemoveScript<GameManager>();
|
|
else
|
|
Instance = this;
|
|
|
|
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
|
|
Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen");
|
|
totalItemCount = 0;
|
|
Score = 0;
|
|
currGameState = GameState.START;
|
|
}
|
|
|
|
protected override void update()
|
|
{
|
|
Cheats();
|
|
|
|
if (currGameState == GameState.START)
|
|
{
|
|
timer -= Time.DeltaTimeF;
|
|
if(scoreText)
|
|
scoreText.GetComponent<TextRenderable>().Text = $"Score: {Score}";
|
|
if(timeText)
|
|
timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0.00")}";
|
|
|
|
if ((timer > 0 && totalItemCount < 0) || Input.GetKeyDown(Input.KeyCode.F1))
|
|
{
|
|
currGameState = GameState.WIN;
|
|
Audio.StopAllSounds();
|
|
SceneManager.ChangeScene(winScene);
|
|
Audio.PlaySFXOnce2D("event:/Music/stingers/game_win");
|
|
}
|
|
else if(timer < 0 || Input.GetKeyDown(Input.KeyCode.F2))
|
|
{
|
|
currGameState = GameState.LOSE;
|
|
Audio.StopAllSounds();
|
|
SceneManager.ChangeScene(loseScene);
|
|
Audio.PlaySFXOnce2D("event:/Music/stingers/game_lose");
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void onDestroy()
|
|
{
|
|
if (Instance == this)
|
|
Instance = null;
|
|
}
|
|
|
|
private void Cheats()
|
|
{
|
|
if (Input.GetKeyDown(Input.KeyCode.Escape))
|
|
{
|
|
Audio.StopAllSounds();
|
|
SceneManager.ChangeScene(97158628);
|
|
}
|
|
}
|
|
|
|
}
|