-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameManager.cs
116 lines (96 loc) · 2.71 KB
/
GameManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
using System;
public class GameManager : MonoBehaviour
{
public GameObject GameOverPanel;
public GameObject Score;
private Canvas canvas;
public TextMeshProUGUI currentScoreText;
public TextMeshProUGUI bestScoreText;
public TextMeshProUGUI bestScoreString;
public TextMeshProUGUI scoreTextString;
public TextMeshProUGUI timerText;
public TextMeshProUGUI currencyText;
int currentScore;
private int currency;
public double timeLeft;
Player player;
private void Awake()
{
player = GameObject.Find("Player").GetComponent<Player>();
}
void Start()
{
currentScore = 0;
//PlayerPrefs.SetInt("BestScore", 0); //ak chces vynulovat best skore pri kazdom spusteni
bestScoreText.text = PlayerPrefs.GetInt("BestScore", 0).ToString();
currency = PlayerPrefs.GetInt("Currency", 0);
currencyText.text = "• " + PlayerPrefs.GetInt("Currency", 0).ToString();
SetScore();
}
void FixedUpdate()
{
Timer();
if (Input.GetKeyDown(KeyCode.Escape))
SceneManager.LoadScene("Menu");
}
public void CallGameOver()
{
StartCoroutine(GameOver());
//StopTimer();
}
IEnumerator GameOver()
{
yield return new WaitForSeconds(0.5f);
canvas = Score.GetComponent<Canvas>();
canvas.sortingOrder = 2;
GameOverPanel.SetActive(true);
yield break;
}
public void Restart()
{
SceneManager.LoadScene("Game");
}
public void AddScore()
{
//TODO: nastavit aby bod pridavalo prejdenie prekazky, nie zbieranie bodu - pridanim timera bod pridava len cas
currentScore++;
if (currentScore > PlayerPrefs.GetInt("BestScore", 0))
{
PlayerPrefs.SetInt("BestScore", currentScore);
bestScoreText.text = currentScore.ToString();
Debug.Log("text:" + bestScoreText.text);
}
SetScore();
}
void SetScore()
{
currentScoreText.text = currentScore.ToString();
}
public void Timer()
{
if ((timeLeft > -1) && (player.isDead == false))
{
timeLeft -= Time.fixedDeltaTime;
timerText.text = timeLeft.ToString("F");
}
else if (timeLeft < 0)
{
timerText.text = "0.00";
}
}
public void AddTime()
{
timeLeft += 3;
}
public void AddCurrency()
{
currency++;
currencyText.text = "• " + currency.ToString();
PlayerPrefs.SetInt("Currency", currency);
}
}