/
GameManager.cs
146 lines (94 loc) · 2.61 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
System.Random rand = new System.Random();
public GameObject exit;
public Sprite red;
public Sprite green;
public Sprite blue;
public Sprite yellow;
public float speedMinInSeconds = 0.5f;
public float speedMaxInSeconds = 1.5f;
public DColor[] colors;
public int numberOfPlayToShowInterstitial = 20;
public Text textScore;
public Transform dotPrefab;
int _point = 0;
int point
{
get
{
return _point;
}
set
{
_point = value;
textScore.text = _point.ToString();
}
}
public CanvasGroup[] canvasGroups;
[System.NonSerialized]
public bool isGameOver = false;
void Awake()
{
exit.SetActive(true);
isGameOver = true;
Application.targetFrameRate = 60;
ResetUIElement();
transform.position = Vector3.zero;
}
void ResetUIElement()
{
isGameOver = true;
textScore.text = "TAP TO BEGIN";
InputTouch.OnTouched += OnTouched;
}
void OnTouched(TouchDirection td)
{
isGameOver = true;
DOStart();
}
public void DOStart()
{
isGameOver = false;
InputTouch.OnTouched -= OnTouched;
FindObjectOfType<Floor>().DOEnable();
DOCreateDot();
point = 0;
}
void DOCreateDot()
{
var inst = Instantiate(dotPrefab) as Transform;
inst.parent = transform;
inst.GetComponent<DBase>().SetColor(colors[rand.Next(0, colors.Length)]);
inst.transform.position = new Vector3(FindObjectOfType<Floor>().GetPositionForDot(), 1.2f * Camera.main.orthographicSize, 0);
Invoke("DOCreateDot", UnityEngine.Random.Range(speedMinInSeconds, speedMaxInSeconds));
}
public void GameOver()
{
exit.SetActive(true);
isGameOver = true;
FindObjectOfType<Floor>().DODisable();
Utils.SetBest(point);
var dots = FindObjectsOfType<Dot>();
foreach (var d in dots)
{
if (d != null && d.gameObject != null)
Destroy(d.gameObject);
}
CancelInvoke("DOCreateDot");
textScore.text = "BEST " + Utils.GetBest();
StartCoroutine(DelayTouch(1f));
}
public void Add1Point()
{
point++;
}
IEnumerator DelayTouch(float value)
{
yield return new WaitForSeconds(value);
InputTouch.OnTouched += OnTouched;
}
}