-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameManager.cs
108 lines (92 loc) · 2.56 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
[Header("Score")]
[Space]
public List<float> Score;
public List<float> ScoreMultiplier;
public string player1Highscore = "player1Highscore";
public string player2Highscore = "player2Highscore";
public float Timer;
public float EndTime;
public bool StartCountingScore = false;
void Awake()
{
if (Instance != null && Instance != this)
Destroy(this);
else
Instance = this;
Timer = 120f;
}
private void Update()
{
UIManager.Instance.Multi(ScoreMultiplier);
if (StartCountingScore)
{
Timer -= Time.deltaTime;
}
if (Timer <= EndTime)
{
Debug.Log("Setting active!");
StartCoroutine(EndTimer());
}
}
private IEnumerator EndTimer()
{
Time.timeScale = 0f;
UIManager.Instance.EndMenuStart(true);
GameManager.Instance.CheckHighscores();
UIManager.Instance.SetScoresPlayers();
yield return null;
}
void FixedUpdate()
{
//score adding based on time
if (StartCountingScore)
{
Score[0] += IncreaseScore(1, ScoreMultiplier[0]);
Score[1] += IncreaseScore(1, ScoreMultiplier[1]);
}
else
{
for (int i = 0; i < Score.Count; i++)
{
Score[i] = 0;
}
}
}
/// <summary>
/// Multiplies the Multiplier by the score and returns the score that needs to be added
/// </summary>
/// <param name="ScoreAmount"></param>
/// <param name="multi"></param>
/// <returns></returns>
public float IncreaseScore(float ScoreAmount, float multi)
{
ScoreAmount *= multi;
return ScoreAmount;
}
public void CheckHighscores()
{
if (GetFloat(player1Highscore) <= Score[0])
{
SetFloat(player1Highscore, Score[0]);
}
if (GetFloat(player2Highscore) <= Score[1])
{
SetFloat(player2Highscore, Score[1]);
}
}
public void SetFloat(string KeyName, float Value)
{
PlayerPrefs.SetFloat(KeyName, Value);
}
public float GetFloat(string KeyName)
{
return PlayerPrefs.GetFloat(KeyName);
}
}