1
Fork 0
mirror of https://github.com/Steffo99/beat-td.git synced 2024-11-23 15:54:18 +00:00
beat-td/Assets/Scripts/GameStatus.cs

62 lines
1.4 KiB
C#
Raw Permalink Normal View History

2018-04-22 12:07:55 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2018-04-23 11:50:24 +00:00
using UnityEngine.SceneManagement;
2018-04-22 12:07:55 +00:00
public class GameStatus : MonoBehaviour {
public int money = 0;
public int lives = 10;
2018-04-23 11:50:24 +00:00
public int[] towerCosts = new int[] { 0, 0, 0 };
2018-04-23 18:09:13 +00:00
public GameObject moneyTextObject = null;
2018-04-23 11:50:24 +00:00
private SongData songData;
2018-04-22 12:07:55 +00:00
private Text moneyText;
2018-04-23 11:50:24 +00:00
private bool gameOver;
2018-04-22 12:07:55 +00:00
void Start()
{
moneyText = moneyTextObject.GetComponent<Text>();
2018-04-23 11:50:24 +00:00
songData = GetComponent<SongData>();
2018-04-22 12:07:55 +00:00
}
void Update()
{
2018-04-23 11:50:24 +00:00
if (moneyText != null)
{
moneyText.text = money.ToString();
}
if (lives <= 0 && !gameOver)
{
GameOver();
}
else if(gameOver)
{
GameObject.FindGameObjectWithTag("Score").GetComponent<Text>().text = "You survived " + songData.songTime.ToString("0.0") + " seconds.";
Destroy(gameObject);
}
}
void GameOver()
{
gameOver = true;
DontDestroyOnLoad(gameObject);
foreach(Transform child in transform)
{
Destroy(child.gameObject);
}
Time.timeScale = 0;
GetComponent<AudioSource>().Stop();
SceneManager.LoadScene("Over");
2018-04-22 12:07:55 +00:00
}
public void EnemyFinishedPath(GameObject enemy)
{
lives -= enemy.GetComponent<EnemyStatus>().livesCost;
Destroy(enemy);
}
}