MiniGameManager.cs
2.39 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public enum GameState
{
Ready,
Play,
End
}
public class MiniGameManager : MonoBehaviour
{
public List<Rabbit> m_rabbits;
static public GameState gameState;
public GameObject UIButton;
public Text timeText;
public Text scoreText;
private int score = 0;
private float time = 0f;
private float sec = 0f;
private int playTime = 30;
void Start()
{
SetSceneReady();
}
public void SetSceneReady()
{
gameState = GameState.Ready;
timeText.text = "00 : " + playTime.ToString("D2");
ResetRabbits();
}
public void LoadMainScene()
{
// 로딩바?
SceneManager.LoadScene("Main");
}
void ResetRabbits()
{
for (int i = 0; i < m_rabbits.Count; i++)
{
m_rabbits[i].None();
}
}
void ExitRabbits()
{
for (int i = 0; i < m_rabbits.Count; i++)
{
if (m_rabbits[i].state != RabbitState.Die && m_rabbits[i].state != RabbitState.None)
m_rabbits[i].Exit();
}
}
public void ShowScore()
{
gameState = GameState.End;
scoreText.text = score + " 마리를 잡았습니다!";
SetGamePanel.Instance.SetPanelOn();
scoreText.gameObject.SetActive(true);
UIButton.SetActive(true);
}
void Update()
{
if (gameState == GameState.Play)
{
time += Time.deltaTime;
sec = Mathf.Ceil(playTime - time);
timeText.text = "00 : " + ((int)sec).ToString("D2");
if (sec <= 0)
{
ExitRabbits();
ShowScore();
}
if (Input.GetMouseButtonDown(0))
{
Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(touchPos, Vector2.zero);
if (hit)
{
int num = int.Parse(hit.collider.gameObject.name);
if (m_rabbits[num].state == RabbitState.Idle)
{
score += 1;
m_rabbits[num].Die();
}
}
}
}
else
return;
}
}