VioletaBabel

32. 타워 디펜스게임 본문

BCA/4. Unity
32. 타워 디펜스게임
Beabletoet 2018. 5. 3. 11:59
타워디펜스 길 찍은 툴 : http://violetababel.tistory.com/409

그냥 닷넷제이슨 에셋에 쑤셔넣으면 빌드하고나면 문제가 되더라
에셋스토어에서 JSON .NET For Unity (PARENTELEMENT, LLC꺼) 넣어서 아래처럼 하니까 잘 되었음 (만들고 불러오는거 둘 다 보려면 DataUI.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
//UpgradeButtonScript.cs
using UnityEngine;
 
public class UpgradeButtonScript : MonoBehaviour
{
    TowerManager TheTowerManager;
    PlayerValue ThePlayerValue;
    // Use this for initialization
    void Start()
    {
        TheTowerManager = TowerManager.instance;
        ThePlayerValue = PlayerValue.instance;
    }
    // Update is called once per frame
    void Update()
    {
 
    }
    private void OnMouseDown()
    {
        int x = TheTowerManager.intClickTowerX;
        int y = TheTowerManager.intClickTowerY;
        int type = TheTowerManager.towerTypeMap[y * 20 + x];
        GameObject nowTower = TheTowerManager.towerObjectMap[y * 20 + x];
        if (x > -1)
        {
            if (type.Equals(0))
            {//각 타입에 맞춰 레벨업 프라이스와 데미지 변경
                if (nowTower.GetComponentInChildren<tower>().levelUpPrice <= ThePlayerValue.gold)
                {
                    ThePlayerValue.gold -= nowTower.GetComponentInChildren<tower>().levelUpPrice;
                    ThePlayerValue.setGold();
                    nowTower.GetComponentInChildren<tower>().dam = (int)((float)nowTower.GetComponentInChildren<tower>().dam * 1.2f);
                    nowTower.GetComponentInChildren<tower>().PlusLevelUpPrice();
                    TheTowerManager.powerUpButton.GetComponent<buttonShowPrice>().setPrice(nowTower.GetComponentInChildren<tower>().levelUpPrice);
                }
            }
            else if (type.Equals(1))
            {
                if (nowTower.GetComponent<tower1>().levelUpPrice <= ThePlayerValue.gold)
                {
                    ThePlayerValue.gold -= nowTower.GetComponent<tower1>().levelUpPrice;
                    ThePlayerValue.setGold();
                    nowTower.GetComponent<tower1>().dam = (int)((float)nowTower.GetComponent<tower1>().dam * 1.2f);
                    nowTower.GetComponent<tower1>().PlusLevelUpPrice();
                    TheTowerManager.powerUpButton.GetComponent<buttonShowPrice>().setPrice(nowTower.GetComponent<tower1>().levelUpPrice);
                }
 
            }
            else if (type.Equals(2))
            {
                if (nowTower.GetComponentInChildren<tower2>().levelUpPrice <= ThePlayerValue.gold)
                {
                    ThePlayerValue.gold -= nowTower.GetComponentInChildren<tower2>().levelUpPrice;
                    ThePlayerValue.setGold();
                    nowTower.GetComponentInChildren<tower2>().dam = (int)((float)nowTower.GetComponentInChildren<tower2>().dam * 1.2f);
                    nowTower.GetComponentInChildren<tower2>().PlusLevelUpPrice();
                    TheTowerManager.powerUpButton.GetComponent<buttonShowPrice>().setPrice(nowTower.GetComponentInChildren<tower2>().levelUpPrice);
                }
 
            }
        }
    }
}
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//TowerManager.cs
using System.Collections.Generic;
using UnityEngine;
 
public class TowerManager : Singleton<TowerManager>
{
    public GameObject SFXBarComponent;
    private OptionBar SFXBar;
    public float maxVol = 1.0f;
    public AudioClip buildSoundSource;
    private AudioSource buildSound;
    public GameObject clickPointer = null;
    public GameObject powerUpButton = null;
    public GameObject deleteTowerButton = null;
    public GameObject[] tower = null;
    private Dictionary<int, Queue<GameObject>> towerPool = new Dictionary<int, Queue<GameObject>>();
    public int[] towerKeyValue = null;
    public bool[] buildMap = new bool[240];
    public int[] towerTypeMap = new int[240];
    public GameObject[] towerTransSprite = null;
    public GameObject[] towerTrans = null;
    public bool boolBuilding = false;
    public int intClickTowerX = -1, intClickTowerY = -1;
    public int towerType = 0;
    public int[] price = new int[5];
    public bool onTheBuildBlock = false;
    public GameObject[] towerObjectMap = new GameObject[240];
    // Use this for initialization
    void Start()
    {
        SFXBarComponent = GameObject.FindGameObjectWithTag("SFXBar");
        SFXBar = SFXBarComponent.GetComponent<OptionBar>();
        buildSound = GetComponent<AudioSource>();
        CreateTowerPool();
        for (int i = 0; i < 5++i)
        {
            if (i != 3)
                towerTrans[i] = Instantiate(towerTransSprite[i], new Vector3(1001000), Quaternion.identity, transform);
        }
    }
 
    // Update is called once per frame
    void Update()
    {
        maxVol = SFXBar.scale;
        buildSound.volume = maxVol;
        if (boolBuilding)
        {
            if (PlayerValue.instance.gold >= price[towerType])
                building();
            else
                boolBuilding = false;
        }
 
        else if (Input.GetMouseButtonDown(0))
        {
            Vector3 nowPos = Input.mousePosition;
            int nowX = (int)nowPos.x / 64, nowY = (int)nowPos.y / 64;
            if (nowX > -1 && nowX < 20 && nowY > -1 && nowY < 11)
            {
                //지금 해야하는 것은 업그레이드 버튼 활성화시키기.
                if (towerTypeMap[nowY * 20 + nowX].Equals(-1|| towerTypeMap[nowY * 20 + nowX].Equals(4))
                {//아무것도 아닌 곳에 클릭했을 때. 팝업 위를 클릭했는지 판단 필요.
                    if (intClickTowerX == -1)
                    {
                        clickPositionInit();
                    }
                    else if (!(nowPos.x / 100 > towerObjectMap[intClickTowerY * 20 + intClickTowerX].transform.position.x - 0.975f
                            && nowPos.x / 100 < towerObjectMap[intClickTowerY * 20 + intClickTowerX].transform.position.x + 0.975f
                            && nowPos.y / 100 > towerObjectMap[intClickTowerY * 20 + intClickTowerX].transform.position.y + 0.3f
                            && nowPos.y / 100 < towerObjectMap[intClickTowerY * 20 + intClickTowerX].transform.position.y + 1.26f))
                    {
                        clickPositionInit();
                    }
                }
                else
                {//무언가 있는 곳에 클릭함
                    if (nowX.Equals(intClickTowerX) && nowY.Equals(intClickTowerY))
                    {//근데 다시 지 자리 클릭임
                        clickPositionInit();
                    }
                    else
                    {//아님, 다른 타워임. 여기서도 팝업 위를 클릭했는지 판단해야함.
                        if (intClickTowerX > -1)
                        {//클릭을 했었음
                            if (!(nowPos.x / 100 > towerObjectMap[intClickTowerY * 20 + intClickTowerX].transform.position.x - 0.975f
                            && nowPos.x / 100 < towerObjectMap[intClickTowerY * 20 + intClickTowerX].transform.position.x + 0.975f
                            && nowPos.y / 100 > towerObjectMap[intClickTowerY * 20 + intClickTowerX].transform.position.y + 0.3f
                            && nowPos.y / 100 < towerObjectMap[intClickTowerY * 20 + intClickTowerX].transform.position.y + 1.26f))
                            {
                                setClickPositionPos(nowX, nowY);
                            }
                        }
                        else if (intClickTowerX == -1)
                        {//클릭한 적 없었음
                            setClickPositionPos(nowX, nowY);
                        }
                    }
                }
            }
        }
    }
 
    public void clickPositionInit()
    {
        clickPointer.transform.position = new Vector3(1001000);
        intClickTowerX = -1;
        intClickTowerY = -1;
    }
    public void setClickPositionPos(int nowX, int nowY)
    {
        clickPointer.transform.position = new Vector3(nowX * 0.64f + 0.32f, nowY * 0.64f + 0.32f, 0);
        intClickTowerY = nowY;
        intClickTowerX = nowX;
        //여기서 버튼을 위치로 가져오면서 가격도 변하게 한다.
        if (towerTypeMap[nowY * 20 + nowX].Equals(0))
        {
            int p = towerObjectMap[nowY * 20 + nowX].GetComponentInChildren<tower>().levelUpPrice;
            powerUpButton.GetComponent<buttonShowPrice>().setPrice(towerObjectMap[nowY * 20 + nowX].GetComponentInChildren<tower>().levelUpPrice);
        }
        else if (towerTypeMap[nowY * 20 + nowX].Equals(1))
        {
            int p = towerObjectMap[nowY * 20 + nowX].GetComponent<tower1>().levelUpPrice;
            powerUpButton.GetComponent<buttonShowPrice>().setPrice(towerObjectMap[nowY * 20 + nowX].GetComponent<tower1>().levelUpPrice);
        }
        else if (towerTypeMap[nowY * 20 + nowX].Equals(2))
        {
            int p = towerObjectMap[nowY * 20 + nowX].GetComponentInChildren<tower2>().levelUpPrice;
            powerUpButton.GetComponent<buttonShowPrice>().setPrice(towerObjectMap[nowY * 20 + nowX].GetComponentInChildren<tower2>().levelUpPrice);
        }
    }
 
    public void CreateTowerPool()
    {
        int tags = 0;
        for (int i = 0; i < 5++i)
        {
 
            if (tower[i].tag.Contains("0"))
                tags = 0;
            else if (tower[i].tag.Contains("1"))
                tags = 1;
            else if (tower[i].tag.Contains("2"))
                tags = 2;
            else if (i.Equals(3))
                continue;
            else if (tower[i].tag.Contains("4"))
                tags = 4;
            towerKeyValue[i] = tags;
            if (!towerPool.ContainsKey(towerKeyValue[i]))
                towerPool.Add(towerKeyValue[i], new Queue<GameObject>());
 
            for (int j = 0; j < 240++j)
            {
                GameObject thisObj = Instantiate(tower[i], new Vector3(1001000), Quaternion.identity, transform);
                thisObj.SetActive(false);
                towerPool[towerKeyValue[i]].Enqueue(thisObj);
                towerObjectMap[j] = null;
            }
        }
    }
 
    public GameObject PopTowerByPool(int towerType, Vector3 pos)
    {
        GameObject thisTower = towerPool[towerType].Dequeue();
        thisTower.transform.position = pos;
        thisTower.SetActive(true);
        towerPool[towerType].Enqueue(thisTower);
        buildSound.PlayOneShot(buildSoundSource);
        return thisTower;
    }
 
    public void setBuildMap()
    {
        for (int i = 0; i < 240++i)
        {
            towerTypeMap[i] = -1;
            if ((i % 20> 17 && i > 59)
                buildMap[i] = false;
            else if (i > 213)
                buildMap[i] = false;
            else if (i > 194 && i < 200)
                buildMap[i] = false;
            else if (i > 175 && i < 180)
                buildMap[i] = false;
            else if (makePath.instance.routeMap[i])
                buildMap[i] = false;
            else
                buildMap[i] = true;
        }
        buildMap[200= false;
    }
 
    public void building()
    {
        //돈이 되는지 선확인할 것
        Vector3 nowPos = Input.mousePosition;
        int nowX = (int)nowPos.x / 64, nowY = (int)nowPos.y / 64;
        if (nowX > -1 && nowX < 20 && nowY > -1 && nowY < 11)
        {
            clickPositionInit();
            if (towerType != 4)
            {//끈끈이가 아닐 때
                if (buildMap[nowY * 20 + nowX])
                {
                    towerTrans[towerType].transform.position = new Vector3(nowX * 0.64f + 0.32f, nowY * 0.64f + 0.32f, 0);
                    if (!onTheBuildBlock)
                        if (Input.GetMouseButton(0))
                        {
                            towerObjectMap[nowY * 20 + nowX] = PopTowerByPool(towerType, new Vector3(nowX * 0.64f + 0.32f, nowY * 0.64f + 0.32f, 0));
                            PlayerValue.instance.gold -= price[towerType];
                            PlayerValue.instance.setGold();
                            towerTrans[towerType].transform.position = new Vector3(1001000);
                            buildMap[nowY * 20 + nowX] = false;
                            towerTypeMap[nowY * 20 + nowX] = towerType;
                            if (PlayerValue.instance.gold < price[towerType])
                            {
                                boolBuilding = false;
                            }
                        }
                }
                else
                {
                    towerTrans[towerType].transform.position = new Vector3(1001000);
                }
            }
            else
            {//끈끈이일 때
                if (makePath.instance.routeMap[nowY * 20 + nowX] && towerObjectMap[nowY * 20 + nowX] == null)
                {
                    towerTrans[towerType].transform.position = new Vector3(nowX * 0.64f + 0.32f, nowY * 0.64f + 0.32f, 0);
                    if (!onTheBuildBlock)
                        if (Input.GetMouseButton(0))
                        {
                            towerObjectMap[nowY * 20 + nowX] = PopTowerByPool(towerType, new Vector3(nowX * 0.64f + 0.32f, nowY * 0.64f + 0.32f, 0));
                            towerObjectMap[nowY * 20 + nowX].GetComponent<SpiderWebScript>().setPosValue(nowX, nowY);
                            PlayerValue.instance.gold -= price[towerType];
                            PlayerValue.instance.setGold();
                            towerTrans[towerType].transform.position = new Vector3(1001000);
                            towerTypeMap[nowY * 20 + nowX] = towerType;
                            //towerTypeMap[nowY * 20 + nowX] = towerType;
                            if (PlayerValue.instance.gold < price[towerType])
                            {
                                boolBuilding = false;
                            }
                        }
                }
                else
                {
                    towerTrans[towerType].transform.position = new Vector3(1001000);
                }
            }
        }
        else
        {
            towerTrans[towerType].transform.position = new Vector3(1001000);
        }
        if (Input.GetMouseButton(1))
        {
            boolBuilding = false;
            towerTrans[towerType].transform.position = new Vector3(1001000);
        }
    }
 
    public void buildOn(int type)
    {
        boolBuilding = true;
        towerType = type;
    }
 
 
    private void OnMouseEnter()
    {
 
    }
    private void OnMouseExit()
    {
 
    }
 
    public void EveryTowerInit()
    {
        clickPositionInit();
        for (int i = 0; i < 5++i)
        {
            if (i.Equals(3))
                continue;
            foreach (GameObject now in towerPool[i])
            {
                
                now.SetActive(false);
                if(now.tag.Contains("0"))
                {
                    now.GetComponentInChildren<tower>().initTower();
                }
                else if (now.tag.Contains("1"))
                {
                    now.GetComponent<tower1>().initTower();
                }
                else if (now.tag.Contains("2"))
                {
                    now.GetComponentInChildren<tower2>().initTower();
                }
                else if (now.tag.Contains("4"))
                {//여긴 나중에 거미줄 관련 코드 추가
 
                }
            }
        }
        for (int i = 0; i < 240++i)
        {
            towerTypeMap[i] = -1;
            towerObjectMap[i] = null;
        }
        setBuildMap();
        intClickTowerX = -1;
        intClickTowerY = -1;
        onTheBuildBlock = false;
        boolBuilding = false;
        towerType = 0;
    }
}
 
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
//tower2_fire.cs
using UnityEngine;
 
public class tower2_fire : MonoBehaviour
{
    private EffectManager TheEffectManager;
    public int dam = 100;
    // Use this for initialization
    void Start()
    {
        TheEffectManager = EffectManager.instance;
        
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag.Contains("monster"))
        {
            GetComponentInParent<tower2>().onFireSound();
            TheEffectManager.PopEffectByPool(2, collision.transform.position);
            //collision.gameObject.GetComponent<MonsterMove>().hp -= dam;
            collision.gameObject.GetComponent<MonsterMove>().setHP(dam);
        }
    }
}
 
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
//tower2.cs
using System.Collections.Generic;
using UnityEngine;
 
public class tower2 : MonoBehaviour
{
    public GameObject SFXBarComponent;
    private OptionBar SFXBar;
    public float maxVol = 1.0f;
    public AudioClip atkSoundSource;
    private AudioSource atkSound;
    public List<GameObject> collEnemys = new List<GameObject>();
    public int levelUpPrice = 200;
    public int levelUpPriceTerm = 100;
    public GameObject fire;
    public int dam = 100;
    // Use this for initialization
    void Start()
    {
        SFXBarComponent = GameObject.FindGameObjectWithTag("SFXBar");
        SFXBar = SFXBarComponent.GetComponent<OptionBar>();
        dam = 100;
        atkSound = GetComponent<AudioSource>();
    }
 
    // Update is called once per frame
    void Update()
    {
        maxVol = SFXBar.scale;
        atkSound.volume = maxVol;
        if (NightScript.instance.isNight)
        {
            GetComponent<CircleCollider2D>().radius = 1.1f;
        }
        else
        {
            GetComponent<CircleCollider2D>().radius = 2.0f;
        }
        if (!collEnemys.Count.Equals(0))
        {
            if (!fire.activeInHierarchy)
            {
                fire.SetActive(true);
            }
            if(fire.GetComponent<tower2_fire>().dam != dam)
                fire.GetComponent<tower2_fire>().dam = dam;
 
            gameObject.transform.Rotate(00540 * TimeManager.GameTime);
        }
        else
        {
            if (fire.activeInHierarchy)
                fire.SetActive(false);
        }
    }
 
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag.Contains("monster"))
            collEnemys.Add(collision.gameObject);
 
    }
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (NightScript.instance.isNight)
        {
            foreach (Transform child in collision.transform)
            {
                if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder < 0)
                    child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
            }
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        foreach (GameObject go in collEnemys)
        {
            if (go.Equals(collision.gameObject))
            {
                collEnemys.Remove(go);
                break;
            }
        }
        if (collision.tag.Contains("monster"))
        {
            if (NightScript.instance.isNight)
            {
                foreach (Transform child in collision.transform)
                {
                    if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder > 0)
                        child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
                }
            }
        }
    }
    public void PlusLevelUpPrice()
    {
        levelUpPrice += levelUpPriceTerm;
    }
    public void initTower()
    {
        levelUpPrice = 200;
        levelUpPriceTerm = 100;
        dam = 100;
    }
 
    public void onFireSound()
    {
        atkSound.PlayOneShot(atkSoundSource, 0.5f);
    }
}
 
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//tower1.cs
using System.Collections.Generic;
using UnityEngine;
 
public class tower1 : MonoBehaviour
{
    public GameObject SFXBarComponent;
    private OptionBar SFXBar;
    public float maxVol = 1.0f;
    EffectManager TheEffectManager;
    public AudioClip shotSoundSource;
    public AudioSource shotSound;
    private float shotTime = 0.125f;
    public List<GameObject> collEnemys = new List<GameObject>();
    public GameObject gunEf1, gunEf2;
    public int shotPattern = 0;
    public int dam = 15;
    public int levelUpPrice = 50;
    public int levelUpPriceTerm = 25;
    // Use this for initialization
    void Start()
    {
        TheEffectManager = EffectManager.instance;
        shotSound = GetComponent<AudioSource>();
        SFXBarComponent = GameObject.FindGameObjectWithTag("SFXBar");
        SFXBar = SFXBarComponent.GetComponent<OptionBar>();
        dam = 15;
    }
 
    // Update is called once per frame
    void Update()
    {
        maxVol = SFXBar.scale;
        shotSound.volume = maxVol;
        if (NightScript.instance.isNight)
        {
            GetComponent<CircleCollider2D>().radius = 1.1f;
        }
        else
        {
            GetComponent<CircleCollider2D>().radius = 1.5f;
        }
        if (!collEnemys.Count.Equals(0))
        {
            GameObject target = collEnemys[0];
            Quaternion q = new Quaternion();
            Vector3 mdir = target.transform.position - transform.position;
            mdir.Normalize();
            Vector3 eAngle = new Vector3(00, Vector3.Angle(Vector3.up, mdir));
            if (mdir.x > 0)
                eAngle *= -1;
            q.eulerAngles = eAngle;
            transform.rotation = q;
 
            shotTime += TimeManager.GameTime;
 
            switch(shotPattern)
            {
                case 0:
                    if (shotTime>=0.5f)
                    {
                        shotPattern = (shotPattern + 1) % 5;
                        shotTime -= 0.5f;
                        gunEf1.SetActive(true);
                        gunEf2.SetActive(false);
                        //target.GetComponent<MonsterMove>().hp -= dam;
                        target.GetComponent<MonsterMove>().setHP(dam);
                        TheEffectManager.PopEffectByPool(1, target.transform.position + new Vector3(00.1f, 0));
                        shotSound.PlayOneShot(shotSoundSource, 0.7f);
                    }
                        break;
                case 1:
                    if (shotTime >= 0.125f)
                    {
                        shotPattern = (shotPattern + 1) % 5;
                        shotTime -= 0.125f;
                        gunEf1.SetActive(false);
                        gunEf2.SetActive(true);
                        //target.GetComponent<MonsterMove>().hp -= dam;
                        target.GetComponent<MonsterMove>().setHP(dam);
                        TheEffectManager.PopEffectByPool(1, target.transform.position + new Vector3(00.1f, 0));
                        shotSound.PlayOneShot(shotSoundSource, 0.7f);
                    }
                    break;
                case 2:
                    if (shotTime >= 0.125f)
                    {
                        shotPattern = (shotPattern + 1) % 5;
                        shotTime -= 0.125f;
                        gunEf1.SetActive(true);
                        gunEf2.SetActive(false);
                        //target.GetComponent<MonsterMove>().hp -= dam;
                        target.GetComponent<MonsterMove>().setHP(dam);
                        TheEffectManager.PopEffectByPool(1, target.transform.position + new Vector3(00.1f, 0));
                        shotSound.PlayOneShot(shotSoundSource, 0.7f);
                    }
                    break;
                case 3:
                    if (shotTime >= 0.125f)
                    {
                        shotPattern = (shotPattern + 1) % 5;
                        shotTime -= 0.125f;
                        gunEf1.SetActive(false);
                        gunEf2.SetActive(true);
                        //target.GetComponent<MonsterMove>().hp -= dam;
                        target.GetComponent<MonsterMove>().setHP(dam);
                        TheEffectManager.PopEffectByPool(1, target.transform.position+new Vector3(0,0.1f,0));
                        shotSound.PlayOneShot(shotSoundSource, 0.7f);
                    }
                    break;
                case 4:
                    if (shotTime >= 0.125f)
                    {
                        shotPattern = (shotPattern + 1) % 5;
                        gunEf1.SetActive(false);
                        gunEf2.SetActive(false);
                    }
                    break;
            }
        }
        else
        {
            shotPattern = 0;
            shotTime = 0.5f;
            gunEf1.SetActive(false);
            gunEf2.SetActive(false);
        }
    }
    public void PlusLevelUpPrice()
    {
        levelUpPrice += levelUpPriceTerm;
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag.Contains("monster"))
            collEnemys.Add(collision.gameObject);
    }
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (NightScript.instance.isNight)
        {
            foreach (Transform child in collision.transform)
            {
                if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder < 0)
                    child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
            }
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        foreach (GameObject go in collEnemys)
        {
            if (go.Equals(collision.gameObject))
            {
                collEnemys.Remove(go);
                break;
            }
        }
        if (collision.tag.Contains("monster"))
        {
            if (NightScript.instance.isNight)
            {
                foreach (Transform child in collision.transform)
                {
                    if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder > 0)
                        child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
                }
            }
        }
    }
    public void initTower()
    {
        shotTime = 0.125f;
        levelUpPrice = 50;
        levelUpPriceTerm = 25;
        dam = 15;
        shotPattern = 0;
    }
}
 
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
147
148
149
150
151
//tower.cs
using System.Collections.Generic;
using UnityEngine;
 
public class tower : MonoBehaviour
{
    public GameObject SFXBarComponent;
    private OptionBar SFXBar;
    public float maxVol = 1.0f;
    public AudioClip bombSoundSource;
    private AudioSource bombSound;
    private BulletManager TheBulletManager = null;
    //private GameObject closeEnemy = null;
    private float shotTime = 0;
    public int levelUpPrice = 100;
    public int levelUpPriceTerm = 50;
    public int dam = 50;
 
    public List<GameObject> collEnemys = new List<GameObject>();
    // Use this for initialization
    void Start()
    {
        SFXBarComponent = GameObject.FindGameObjectWithTag("SFXBar");
        SFXBar = SFXBarComponent.GetComponent<OptionBar>();
        TheBulletManager = BulletManager.instance;
        bombSound = GetComponent<AudioSource>();
        dam = 50;
    }
 
    // Update is called once per frame
    void Update()
    {
        maxVol = SFXBar.scale;
        bombSound.volume = maxVol;
        if (NightScript.instance.isNight)
        {
            GetComponent<CircleCollider2D>().radius = 1.1f;
        }
        else
        {
            GetComponent<CircleCollider2D>().radius = 1.5f;
        }
        if (!collEnemys.Count.Equals(0))
        {
            shotTime += TimeManager.GameTime;
            GameObject target = collEnemys[0];
 
            Quaternion q = new Quaternion();
            Vector3 mdir = target.transform.position - transform.position;
            mdir.Normalize();
            Vector3 eAngle = new Vector3(00, Vector3.Angle(Vector3.up, mdir));
            if (mdir.x > 0)
                eAngle *= -1;
            q.eulerAngles = eAngle;
            transform.rotation = q;
            if (shotTime > 0.5f)
            {
                shotTime = 0;
 
 
                //GameObject bullet = TheBulletManager.PopBulletByPool(0, transform.position);
                GameObject bullet = TheBulletManager.PopBulletByPool(0, transform.position, dam);
                //bullet.GetComponent<rocket>().dam = dam;
                bullet.GetComponent<rocket>().targetPos = target.transform.position;
                bullet.transform.rotation = transform.rotation;
                bullet.GetComponent<rocket>().nowTower = GetComponent<tower>();
            }
        }
        else
        {
            shotTime = 0.5f;
        }
    }
 
    public void initTower()
    {
        shotTime = 0;
        levelUpPrice = 100;
        levelUpPriceTerm = 50;
        dam = 50;
    }
 
    public void PlusLevelUpPrice()
    {
        levelUpPrice += levelUpPriceTerm;
    }
    
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag.Contains("monster"))
        {
            collEnemys.Add(collision.gameObject);
            //if (closeEnemy == null)
            //    closeEnemy = collision.gameObject;
            //else
            //{
            //    float nowLen = Vector3.Distance(closeEnemy.transform.position, transform.position);
            //    float newLen = Vector3.Distance(collision.gameObject.transform.position, transform.position);
            //    if (nowLen > newLen)
            //        closeEnemy = collision.gameObject;
            //    if (nowLen > 0.5f && newLen > 0.5f)
            //        closeEnemy = null;
            //}
        }
 
    }
 
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (NightScript.instance.isNight)
        {
            foreach (Transform child in collision.transform)
            {
                if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder < 0)
                    child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
            }
        }
    }
 
    private void OnTriggerExit2D(Collider2D collision)
    {
        foreach (GameObject go in collEnemys)
        {
            if (go.Equals(collision.gameObject))
            {
                collEnemys.Remove(go);
                break;
            }
 
 
        }
 
        if (collision.tag.Contains("monster"))
        {
            if (NightScript.instance.isNight)
            {
                foreach (Transform child in collision.transform)
                {
                    if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder > 0)
                        child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
                }
            }
        }
    }
 
    public void playShotSound()
    {
        bombSound.PlayOneShot(bombSoundSource, 0.3f);
    }
}
 
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
//TimeManager.cs
using UnityEngine;
 
public class TimeManager : MonoBehaviour
{
    static public float GameTime = 0;
    static private bool _timeStop = true;
    static public bool bTimeStop
    {
        get
        {
            return _timeStop;
        }
        set
        {
            _timeStop = value;
        }
    }
    // Use this for initialization
    void Start()
    {
        
 
    }
 
    // Update is called once per frame
    void Update()
    {
        if (bTimeStop)
            GameTime = 0;
        else
            GameTime = Time.deltaTime;
    }
}
 
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
//tileScript.cs
using UnityEngine;
 
public class tileScript : MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        GameObject gameTile = Resources.Load("TileObject"typeof(GameObject)) as GameObject;
        makeTile(gameTile, "rpgTile018"new Vector3(0.32f, 7.36f, 0));
        makeTile(gameTile, "rpgTile020"new Vector3(12.48f, 7.36f, 0));
        makeTile(gameTile, "rpgTile036"new Vector3(0.32f, 0.32f, 0));
        makeTile(gameTile, "rpgTile038"new Vector3(12.48f, 0.32f, 0));
 
        for (int i = 1; i < 19++i)
        {
            makeTile(gameTile, "rpgTile037"new Vector3(0.32f + (float)i * 0.64f, 0.32f, 0));
            if (i < 11)
            {
                makeTile(gameTile, "rpgTile018"new Vector3(0.32f, 7.36f - 0.64f * (float)i, 0));
                makeTile(gameTile, "rpgTile020"new Vector3(12.48f, 7.36f - 0.64f * (float)i, 0));
            }
        }
        for (int i = 0; i < 10++i)
            for (int j = 0; j < 18++j)
                makeTile(gameTile, "rpgTile019"new Vector3(0.96f + (float)j * 0.64f, 0.96f + (float)i * 0.64f, 0));
 
        //호수
        makeTile(gameTile, "rpgTile044"new Vector3(0.96f, 7.36f, 0));
        for(int i = 0; i < 16++i)
            makeTile(gameTile, "rpgTile045"new Vector3(1.6f+0.64f*(float)i, 7.36f, 0));
        makeTile(gameTile, "rpgTile046"new Vector3(11.84f, 7.36f, 0));
 
 
        //나무
        makeTile(gameTile, "rpgTile199"new Vector3(9.92f, 6.72f, 0), 15);
        makeTile(gameTile, "rpgTile179"new Vector3(9.92f, 7.36f, 0), 15);
        makeTile(gameTile, "rpgTile196"new Vector3(10.56f, 6.72f, 0), 15);
        makeTile(gameTile, "rpgTile176"new Vector3(10.56f, 7.36f, 0), 15);
        makeTile(gameTile, "rpgTile176"new Vector3(9.70f, 7.0f, 0), 16);
        makeTile(gameTile, "rpgTile196"new Vector3(9.70f, 6.36f, 0), 16);
        makeTile(gameTile, "rpgTile196"new Vector3(10.96f, 6.82f, 0), 14);
        makeTile(gameTile, "rpgTile176"new Vector3(10.96f, 7.46f, 0), 14);
 
        makeTile(gameTile, "rpgTile159"new Vector3(10.26f, 6.92f, 0), 14);
        makeTile(gameTile, "rpgTile156"new Vector3(10.16f, 6.82f, 0), 15);
 
        makeTile(gameTile, "rpgTile199"new Vector3(11.36f, 6.72f, 0), 15);
        makeTile(gameTile, "rpgTile179"new Vector3(11.36f, 7.36f, 0), 15);
 
        makeTile(gameTile, "rpgTile195"new Vector3(11.84f, 6.82f, 0), 14);
        makeTile(gameTile, "rpgTile175"new Vector3(11.84f, 7.46f, 0), 14);
        makeTile(gameTile, "rpgTile199"new Vector3(12.34f, 6.72f, 0), 15);
        makeTile(gameTile, "rpgTile179"new Vector3(12.34f, 7.36f, 0), 15);
        makeTile(gameTile, "rpgTile200"new Vector3(12.13f, 6.42f, 0), 16);
        makeTile(gameTile, "rpgTile180"new Vector3(12.13f, 7.06f, 0), 16);
        makeTile(gameTile, "rpgTile195"new Vector3(12.43f, 6.12f, 0), 17);
        makeTile(gameTile, "rpgTile175"new Vector3(12.43f, 6.76f, 0), 17);
 
        makeTile(gameTile, "rpgTile196"new Vector3(11.93f, 5.72f, 0), 17);
        makeTile(gameTile, "rpgTile176"new Vector3(11.93f, 6.36f, 0), 17);
 
        makeTile(gameTile, "rpgTile159"new Vector3(12.55f, 5.72f, 0), 17);
        makeTile(gameTile, "rpgTile160"new Vector3(12.30f, 5.72f, 0), 18);
        makeTile(gameTile, "rpgTile155"new Vector3(12.23f, 5.82f, 0), 16);
        makeTile(gameTile, "rpgTile201"new Vector3(11.84f, 5.44f, 0), 19);
        makeTile(gameTile, "rpgTile181"new Vector3(12.48f, 5.44f, 0), 19);
        makeTile(gameTile, "rpgTile183"new Vector3(9.28f, 6.87f, 0), 19);
        makeTile(gameTile, "rpgTile183"new Vector3(9.48f, 6.97f, 0), 14);
 
        makeTile(gameTile, "rpgTile196"new Vector3(11.93f, 2.92f, 0), 17);
        makeTile(gameTile, "rpgTile176"new Vector3(11.93f, 3.56f, 0), 17);
        makeTile(gameTile, "rpgTile195"new Vector3(12.43f, 3.12f, 0), 17);
        makeTile(gameTile, "rpgTile175"new Vector3(12.43f, 3.76f, 0), 17);
        makeTile(gameTile, "rpgTile200"new Vector3(12.44f, 4.22f, 0), 16);
        makeTile(gameTile, "rpgTile180"new Vector3(12.44f, 4.86f, 0), 16);
        makeTile(gameTile, "rpgTile199"new Vector3(12.03f, 3.42f, 0), 15);
        makeTile(gameTile, "rpgTile179"new Vector3(12.03f, 4.06f, 0), 15);
 
        makeTile(gameTile, "rpgTile200"new Vector3(11.84f, 4.72f, 0), 20);
        makeTile(gameTile, "rpgTile180"new Vector3(11.84f, 5.36f, 0), 20);
 
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    void makeTile(GameObject gameTile, string f, Vector3 position, int order = -10)
    {
        string fileName = "PNG/" + f;
        GameObject instance = Instantiate(gameTile) as GameObject;
        SpriteRenderer pRenderer = instance.AddComponent<SpriteRenderer>();
 
        Sprite tile = Resources.Load(fileName, typeof(Sprite)) as Sprite;
        pRenderer.sprite = tile;
        pRenderer.sortingOrder = order;
        instance.transform.position = position;
        instance.transform.parent = transform;
    }
}
//세로 0~11번 칸, 가로 0~19번 칸
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
//SpiderWebScript.cs
using UnityEngine;
 
public class SpiderWebScript : MonoBehaviour
{
    public AudioClip webSoundSource;
    private AudioSource webSound;
    public int count = 0;
    public int nowX, nowY;
    // Use this for initialization
    void Start()
    {
        webSound = GetComponent<AudioSource>();
        webSoundSource = Resources.Load("Sound/websound"typeof(AudioClip)) as AudioClip;
    }
 
    // Update is called once per frame
    void Update()
    {
        if(count.Equals(40))
        {
            count = 0;
            gameObject.SetActive(false);
            TowerManager.instance.towerObjectMap[nowY * 20 + nowX] = null;
            TowerManager.instance.towerTypeMap[nowY * 20 + nowX] = -1;
            nowX = -1;
            nowY = -1;
            
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.tag.Contains("monster"))
        {
            webSound.PlayOneShot(webSoundSource);
            collision.GetComponent<MonsterMove>().glue = 0.5f+((float)count++/100.0f);
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.tag.Contains("monster"))
        {
            collision.GetComponent<MonsterMove>().glue = 1.0f;
        }
    }
    public void setPosValue(int x, int y)
    {
        nowX = x;
        nowY = y;
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Singleton.cs
using UnityEngine;
 
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
    private static T _instance;
    public static T instance
    {
        get
        {
            if(_instance == null)
            {
                _instance = FindObjectOfType(typeof(T)) as T;
            }
            return _instance;
        }
    }
}
 
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
//rocket.cs
using UnityEngine;
 
public class rocket : MonoBehaviour
{
    private EffectManager TheEffectmanager;
    public Vector3 mdir = Vector3.zero;
    public Vector3 targetPos = Vector3.zero;
    public Vector3 eAngle = Vector3.zero;
    public bool shot = false;
    public int dam = 50;
    public float distance;
    public bool hitTheMark = false;
    public tower nowTower;
    // Use this for initialization
    void Start()
    {
        TheEffectmanager = EffectManager.instance;
    }
 
    // Update is called once per frame
    void Update()
    {
        if (!shot)
            if (!targetPos.Equals(Vector3.zero))
            {
                //Quaternion q = new Quaternion();
                //mdir = targetPos - transform.position;
                //mdir.Normalize();
                //eAngle = new Vector3(0, 0, Vector3.Angle(Vector3.up, mdir));
                //if (mdir.x > 0)
                //    eAngle *= -1;
                //q.eulerAngles = eAngle;
                //transform.rotation = q;
                shot = true;
            }
        transform.position = Vector3.Lerp(transform.position, targetPos, 0.2f);
 
        distance = Vector3.Distance(transform.position, targetPos);
        if (distance < 0.1f)
        {
            TheEffectmanager.PopEffectByPool(0, targetPos);
            rocketBomb();
            gameObject.SetActive(false);
        }
    }
 
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag.Contains("monster"))
        {
            TheEffectmanager.PopEffectByPool(0, collision.transform.position);
            rocketBomb();
            gameObject.SetActive(false);
        }
    }
 
    private void rocketBomb()
    {
        nowTower.playShotSound();
        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 0.5f);
        foreach (Collider2D col in colliders)
        {
            if (col.tag.Contains("monster"))
                //col.gameObject.GetComponent<MonsterMove>().hp -= dam;
                col.gameObject.GetComponent<MonsterMove>().setHP(dam);
        }
        
    }
}
 
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
//RepairHomeScript.cs
using UnityEngine;
 
public class RepairHomeScript : MonoBehaviour
{
    HomeScript TheHomeScript;
    PlayerValue ThePlayerValue;
 
    // Use this for initialization
    void Start()
    {
        TheHomeScript = HomeScript.instance;
        ThePlayerValue = PlayerValue.instance;
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    private void OnMouseDown()
    {
        if (ThePlayerValue.gold >= 3000)
            if ((TheHomeScript.maxHp - TheHomeScript.hp) < 50)
            {
                TheHomeScript.hp = TheHomeScript.maxHp;
                TheHomeScript.setHP(0);
                ThePlayerValue.gold -= 3000;
                ThePlayerValue.setGold();
            }
            else if (TheHomeScript.maxHp - TheHomeScript.hp != 0)
            {
                TheHomeScript.hp += 50;
                TheHomeScript.setHP(0);
                ThePlayerValue.gold -= 3000;
                ThePlayerValue.setGold();
            }
    }
}
 
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
//PlayerValue.cs
using UnityEngine;
 
public class PlayerValue : Singleton<PlayerValue>
{
    public int gold = 100;
    public GameObject dollarSymbol = null;
    public GameObject[] dollarSprite = null;
    public GameObject[] nowDollar = null;
    public GameObject skullPrefab;
    public GameObject skull;
    public GameObject[] nowMonsterNum;
    // Use this for initialization
    void Start()
    {
        GameInit();
        GameObject dollar = Instantiate(dollarSymbol, new Vector3(0.2f, 7.4f, 0), Quaternion.identity, transform);
        dollar.GetComponent<SpriteRenderer>().sortingOrder = 10000;
        for (int i = 0; i < 6++i)
        {
            if (i.Equals(3))
                nowDollar[i] = Instantiate(dollarSprite[1], new Vector3(0.5f + 0.3f * i, 7.4f, 0), Quaternion.identity, transform);
            else
                nowDollar[i] = Instantiate(dollarSprite[0], new Vector3(0.5f + 0.3f * i, 7.4f, 0), Quaternion.identity, transform);
            nowDollar[i].GetComponent<SpriteRenderer>().sortingOrder = 10000;
        }
        skull = Instantiate(skullPrefab, new Vector3(2.5f, 7.4f, 0), Quaternion.identity, transform);
        skull.GetComponent<SpriteRenderer>().sortingOrder = 10000;
        for (int i = 0; i < 2++i)
        {
            nowMonsterNum[i] = Instantiate(dollarSprite[0], new Vector3(2.8f + 0.3f * i, 7.4f, 0), Quaternion.identity, transform);
            nowMonsterNum[i].GetComponent<SpriteRenderer>().sortingOrder = 10000;
        }
    }
 
    // Update is called once per frame
    void Update()
    {
        if (GameManager.bGameStart && TimeManager.GameTime != 0)
            if (Input.GetMouseButtonDown(0|| Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.X))
            {
                int a = Random.Range(13);
                gold += a;
                setGold();
            }
    }
 
    public void GameInit()
    {
        gold = 100;
    }
    public void setGold()
    {
        int[] golds = new int[6];
        for (int i = 0, j = gold, k = 100000; i < 6++i, k /= 10)
        {
            golds[i] = j / k;
            j %= k;
            Destroy(nowDollar[i]);
            nowDollar[i] = Instantiate(dollarSprite[golds[i]], new Vector3(0.5f + 0.3f * i, 7.4f, 0), Quaternion.identity, transform);
            nowDollar[i].GetComponent<SpriteRenderer>().sortingOrder = 10000;
        }
    }
 
    public void setSkullCount(int nowCount)
    {
        int[] skulls = new int[2];
        Destroy(nowMonsterNum[0]);
        Destroy(nowMonsterNum[1]);
        skulls[0= nowCount / 10;
        skulls[1= nowCount % 10;
        nowMonsterNum[0= Instantiate(dollarSprite[skulls[0]], new Vector3(2.8f, 7.4f, 0), Quaternion.identity, transform);
        nowMonsterNum[1= Instantiate(dollarSprite[skulls[1]], new Vector3(3.1f, 7.4f, 0), Quaternion.identity, transform);
        nowMonsterNum[0].GetComponent<SpriteRenderer>().sortingOrder = 10000;
        nowMonsterNum[1].GetComponent<SpriteRenderer>().sortingOrder = 10000;
    }
}
 
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
//PlayButtonScript.cs
using UnityEngine;
 
public class PlayButtonScript : MonoBehaviour
{
    public GameObject[] button = null;
    public bool play = false;
    // Use this for initialization
    void Start()
    {
 
    }
 
    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            togglePlayButton();
        }
    }
    private void OnMouseDown()
    {
        togglePlayButton();
    }
 
    public void togglePlayButton()
    {
        if (!GameManager.bGameStart)
        {
            resetButton();
        }
        else
        {
            play = !play;
            if (play)
            {
                TimeManager.bTimeStop = false;
                button[0].SetActive(false);
                button[1].SetActive(true);
            }
            else
            {
                resetButton();
            }
        }
    }
 
    public void resetButton()
    {
        play = false;
        TimeManager.bTimeStop = true;
        button[0].SetActive(true);
        button[1].SetActive(false);
    }
}
 
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
//OptionBar.cs
using UnityEngine;
 
public class OptionBar : MonoBehaviour
{
    public GameObject[] barEnd = null;
    public GameObject button = null;
    public float scale = 1.0f;
    // Use this for initialization
    void Start()
    {
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    private void OnMouseDrag()
    {
        Vector3 nowPos = button.transform.position;
        float mouseX = Input.mousePosition.x / 100;
        if (mouseX > barEnd[1].transform.position.x)
        {
            nowPos.x = barEnd[1].transform.position.x;
            button.transform.position = nowPos;
        }
        else if(mouseX < barEnd[0].transform.position.x)
        {
            nowPos.x = barEnd[0].transform.position.x;
            button.transform.position = nowPos;
        }
        else
        {
            nowPos.x = mouseX;
            button.transform.position = nowPos;
        }
 
        scale = (button.transform.position.x - barEnd[0].transform.position.x) / (barEnd[1].transform.position.x - barEnd[0].transform.position.x);
    }
}
 
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
//NightTileScript.cs
using UnityEngine;
 
public class NightTileScript : MonoBehaviour
{//얘네 보일땐 24, 안보일땐 -24
    public int x, y;
    // Use this for initialization
    void Start()
    {
 
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    public void setPos(int _x, int _y)
    {
        x = _x;
        y = _y;
    }
}
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
//NightScript.cs
using UnityEngine;
 
public class NightScript : Singleton<NightScript>
{
    //monster의 sortingorder는 19
    public GameObject nightTilePrefab;
    public GameObject[] nightTile = new GameObject[240];
    public bool[] nightMap = new bool[240];
    public bool isNight = false;
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < 240++i)
        {
            Vector3 pos = new Vector3((i % 20* 0.64f + 0.32f, (i / 20* 0.64f + 0.32f, 0);
            nightTile[i] = Instantiate(nightTilePrefab, pos, Quaternion.identity, transform);
            nightTile[i].SetActive(false);
            nightTile[i].GetComponent<NightTileScript>().setPos(i % 20, i / 20);
            nightMap[i] = false;
        }
    }
 
    // Update is called once per frame
    void Update()
    {
        if (isNight)
            NightTime();
        else
            dayTime();
 
        for (int i = 0; i < 240++i)
            if (nightMap[i])
                nightTile[i].SetActive(true);
            else
                nightTile[i].SetActive(false);
    }
 
    public void NightInit()
    {
        for (int i = 0; i < 240++i)
        {
            nightTile[i].SetActive(false);
            nightMap[i] = false;
        }
        isNight = false;
    }
 
    public void NightTime()
    {
        for (int i = 0; i < 240++i)
        {
            if (i.Equals(156|| i.Equals(157))
                continue;
            bool a = true;
            for(int j = -1; j < 2++j)
                for(int k = -1; k < 2++k)
                {
                    int b = i + (j * 20 + k);
                    if(b > -1 && b < 240)
                    {
                        int c = TowerManager.instance.towerTypeMap[b];
                        if (c > -1 && c != 4)
                        {
                            a = false;
                        }
                    }
                }
            if (a)
                nightMap[i] = true;
            else
                nightMap[i] = false;
        }
    }
 
    public void dayTime()
    {
        for (int i = 0; i < 240++i)
            nightMap[i] = false;
    }
}
 
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//MonsterMove.cs
using UnityEngine;
using DG.Tweening;
 
public class MonsterMove : MonoBehaviour
{
    public int nowPos, nextPos, nowX, nowY, nextX, nextY, maxHp, hp, rewardGold, firstMaxHp;
    public GameObject child = null;
    public float speed;
    makePath TheMakePath;
    public bool finishMove, turn;
    PlayerValue ThePlayerValue;
    HomeScript TheHome;
    private float finalMove;
    public float atkTime;
    public float glue = 1.0f;
    public float spidyTime = 0.2f; //깜빡거리는거 재는 시간
    public bool spidyPurple = false;
    public int firstAtkDam;
    public int atkDam;
    // Use this for initialization
    void Start()
    {
        TheMakePath = makePath.instance;
        ThePlayerValue = PlayerValue.instance;
        TheHome = HomeScript.instance;
        RespawnPos();
        firstMaxHp = maxHp;
    }
 
    public void RespawnPos()
    {
        hp = maxHp;
        nowPos = -1;
        nowX = 2;
        nowY = -1;
        nextPos = 0;
        nextX = 2;
        nextY = 0;
        finishMove = false;
        turn = false;
        finalMove = 0.1f;
        atkTime = 0;
        atkDam = firstAtkDam;
    }
 
    public void InitMonster()
    {
        maxHp = firstMaxHp;
        RespawnPos();
    }
 
    void PosInit()
    {
        nowX = TheMakePath.movePath[nowPos].x;
        nowY = TheMakePath.movePath[nowPos].y;
        if (!nextPos.Equals(TheMakePath.movePath.Count))
        {
            nextX = TheMakePath.movePath[nextPos].x;
            nextY = TheMakePath.movePath[nextPos].y;
        }
        turn = false;
    }
 
    // Update is called once per frame
    void Update()
    {
        if (hp <= 0)
        {
            gameObject.SetActive(false);
            maxHp = (int)((float)maxHp * 2f);
            atkDam = (int)((float)atkDam * 1.2f);
            RespawnPos();
            ThePlayerValue.gold += rewardGold;
            PlayerValue.instance.setGold();
            GetComponent<HPBar>().setHpBarSize(hp, maxHp);
            --MonsterManagerScript.instance.waveNowMonster;
            MonsterManagerScript.instance.ShowSkull();
        }
        if (glue < 1)
        {
            spidyTime += TimeManager.GameTime;
            if (spidyTime >= 0.2f)
            {
                spidyTime -= 0.2f;
                if (spidyPurple)
                {
                    child.GetComponent<SpriteRenderer>().DOColor(new Color(111), 0.2f);
                    spidyPurple = false;
                }
                else
                {
                    child.GetComponent<SpriteRenderer>().DOColor(new Color(1, (100.0f / 255.0f), 1), 0.2f);
                    spidyPurple = true;
                }
            }
        }
        else
        {
            child.GetComponent<SpriteRenderer>().DOColor(new Color(111), 0);
            spidyTime = 0.2f;
            spidyPurple = false;
        }
        Quaternion q = new Quaternion();
        Vector3 nowVec = transform.position;
        if (!finishMove)
        {
            Animator ani = GetComponent<Animator>();
            if (nextPos.Equals(TheMakePath.movePath.Count))
            {
                q.eulerAngles = new Vector3(000);
                child.transform.rotation = q;
                //ani.ResetTrigger("left");
                //ani.ResetTrigger("right");
                //ani.ResetTrigger("down");
                //ani.SetTrigger("up");
                finishMove = true;
            }
            else if (nowX < nextX)
            {
                //오른쪽이동
                q.eulerAngles = new Vector3(00270);
                child.transform.rotation = q;
                //if (!turn)
                //{
                //    ani.ResetTrigger("left");
                //    ani.ResetTrigger("up");
                //    ani.ResetTrigger("down");
                //    ani.SetTrigger("right");
                //    turn = true;
                //}
                nowVec += Vector3.right * TimeManager.GameTime * speed * glue;
                transform.position = nowVec;
                if (transform.position.x >= nextX * 0.64f + 0.32f)
                {
                    transform.position = new Vector3(nextX * 0.64f + 0.32f, transform.position.y);
                    ++nowPos;
                    ++nextPos;
                    PosInit();
                }
            }
            else if (nowX > nextX)
            {//왼쪽이동
                q.eulerAngles = new Vector3(0090);
                child.transform.rotation = q;
                //if (!turn)
                //{
                //    ani.ResetTrigger("right");
                //    ani.ResetTrigger("up");
                //    ani.ResetTrigger("down");
                //    ani.SetTrigger("left");
                //    turn = true;
                //}
                nowVec += Vector3.left * TimeManager.GameTime * speed * glue;
                transform.position = nowVec;
                if (transform.position.x <= nextX * 0.64f + 0.32f)
                {
                    transform.position = new Vector3(nextX * 0.64f + 0.32f, transform.position.y);
                    ++nowPos;
                    ++nextPos;
                    PosInit();
                }
            }
            else if (nowY < nextY)
            {//위로 이동
                q.eulerAngles = new Vector3(000);
                child.transform.rotation = q;
                //if (!turn)
                //{
                //    ani.ResetTrigger("left");
                //    ani.ResetTrigger("right");
                //    ani.ResetTrigger("down");
                //    ani.SetTrigger("up");
                //    turn = true;
                //}
                nowVec += Vector3.up * TimeManager.GameTime * speed * glue;
                transform.position = nowVec;
                if (transform.position.y >= nextY * 0.64f + 0.32f)
                {
                    transform.position = new Vector3(transform.position.x, nextY * 0.64f + 0.32f);
                    ++nowPos;
                    ++nextPos;
                    PosInit();
                }
            }
            else if (nowY > nextY)
            {//아래로 이동
                q.eulerAngles = new Vector3(00180);
                child.transform.rotation = q;
                //if (!turn)
                //{
                //    ani.ResetTrigger("left");
                //    ani.ResetTrigger("right");
                //    ani.ResetTrigger("up");
                //    ani.SetTrigger("down");
                //    turn = true;
                //}
                nowVec += Vector3.down * TimeManager.GameTime * speed * glue;
                transform.position = nowVec;
                if (transform.position.y <= nextY * 0.64f + 0.32f)
                {
                    transform.position = new Vector3(transform.position.x, nextY * 0.64f + 0.32f);
                    ++nowPos;
                    ++nextPos;
                    PosInit();
                }
            }
        }
        else
        {
            atkTime += TimeManager.GameTime;
            if (atkTime >= 0.5f)
            {
                Vector3 move = transform.position;
                move.y += finalMove;
                finalMove *= (-1);
                transform.position = move;
                atkTime -= 0.5f;
                if (finalMove < 0)
                    atkTime = 0.5f;
                else
                {
                    TheHome.setHP(atkDam);
                }
            }
        }
    }
 
    public void setHP(int dam)
    {
        float ran = Random.Range(0.9f, 1.1f);
        dam = (int)((float)dam * ran);
        hp -= dam;
        if (hp < 0)
            hp = 0;
        GetComponent<HPBar>().setHpBarSize(hp, maxHp);
    }
}
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//MonsterManagerScript.cs
using System.Collections.Generic;
using UnityEngine;
 
public class MonsterManagerScript : Singleton<MonsterManagerScript>
{
    public GameObject[] monster = null;
    private Dictionary<int, Queue<GameObject>> monsterPool = new Dictionary<int, Queue<GameObject>>();
    public int[] monsterKeyValue = null;
    private Vector3 startDir = new Vector3(1.6f, -0.32f, 0);
    public float spawnTime = 1.0f; // 현 웨이브 중 스폰까지 걸리는 시간 카운트
    public float spawnTerm; // 현 웨이브 중 스폰까지 걸리는 시간
    public float waveTerm; // 현 웨이브가 끝나고 다음 웨이브까지 기다리는 시간
    public float waveWaitTime; // 현 웨이브가 끝나고 다음 웨이브까지 기다리는 시간 카운트
    public int waveMaxMonster; // 현 웨이브 최대 마리 수
    public int waveMonsterCount; // 현 웨이브 현재 나온 마리 수
    public int waveMaxType;//현 웨이브에 나올 수 있는 몬스터 타입 한계
    public int waveNowMonster = 0//현재 맵에 존재하는 몬스터 수
    public bool isWaving = false;
    // Use this for initialization
    void Start()
    {
        CreateMonsterPool();
        waveNowMonster = 0;
        waveMaxType = 1;//-1만큼 랜덤으로 뜸
        waveMaxMonster = 4;
        waveTerm = 3.0f;
    }
 
    // Update is called once per frame
    void Update()
    {
        if (GameManager.bGameStart)
        {
            if (!isWaving)
            {
                isWaving = true;
                spawnTerm = Random.Range(0.5f, 1.5f);
                if (waveMaxMonster < 20)
                {
                    if (waveMaxMonster > 15)
                        waveMaxType = 5;
                    else if (waveMaxMonster > 12)
                        waveMaxType = 4;
                    else if (waveMaxMonster > 9)
                        waveMaxType = 3;
                    else if (waveMaxMonster > 6)
                        waveMaxType = 2;
                    else
                        waveMaxType = 1;
                    ++waveMaxMonster;
                }
                waveNowMonster = 0;
                waveMonsterCount = 0;
                waveWaitTime = 0;
                spawnTime = 0;
                ShowSkull();
            }
 
            //spawnTime += TimeManager.GameTime;
            //if (spawnTime >= 1.0f)
            //{
            //    PopMonsterByPool(1);
            //    spawnTime -= 1.0f;
            //}
            if (waveMonsterCount.Equals(waveMaxMonster))
            {
                if (waveNowMonster.Equals(0))
                {
                    waveWaitTime += TimeManager.GameTime;
                    if (waveWaitTime >= waveTerm)
                    {
                        isWaving = false;
                        waveWaitTime = 0;
                        if (NightScript.instance.isNight)
                            NightScript.instance.isNight = false;
                        else
                            NightScript.instance.isNight = true;
                    }
                }
            }
            else
            {
                spawnTime += TimeManager.GameTime;
                if(spawnTime >= spawnTerm)
                {
                    ++waveMonsterCount;
                    PopMonsterByPool(Random.Range(0, waveMaxType));
                    spawnTime -= spawnTerm;
                }
            }
        }
        //else
        //{
        //    //spawnTime = 1.0f;
        //}
    }
 
    public void ShowSkull()
    {
        PlayerValue.instance.setSkullCount(waveNowMonster);
    }
    public void CreateMonsterPool()
    {
        int tags = 0;
        for (int i = 0; i < 5++i)
        {
            if (monster[i].tag.Contains("0"))
                tags = 0;
            else if (monster[i].tag.Contains("1"))
                tags = 1;
            else if (monster[i].tag.Contains("2"))
                tags = 2;
            else if (monster[i].tag.Contains("3"))
                tags = 3;
            else if (monster[i].tag.Contains("4"))
                tags = 4;
            monsterKeyValue[i] = tags;
            if (!monsterPool.ContainsKey(monsterKeyValue[i]))
                monsterPool.Add(monsterKeyValue[i], new Queue<GameObject>());
 
            for (int j = 0; j < 20++j)
            {
                GameObject thisObj = Instantiate(monster[i], new Vector3(1.6f, -0.32f, 0), Quaternion.identity, transform);
                thisObj.GetComponent<HPBar>().MakeHPBar();
                monsterPool[monsterKeyValue[i]].Enqueue(thisObj);
                thisObj.SetActive(false);
            }
        }
    }
 
    public GameObject PopMonsterByPool(int monsterType)
    {
        GameObject thisMonster = monsterPool[monsterType].Dequeue();
        thisMonster.transform.position = startDir;
        thisMonster.SetActive(true);
        thisMonster.GetComponent<MonsterMove>().RespawnPos();
        if(NightScript.instance.isNight)
        {
            foreach (Transform child in thisMonster.transform)
            {
 
                if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder > 0)
                    child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
            }
        }
        else
        {
            foreach (Transform child in thisMonster.transform)
            {
                if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder < 0)
                    child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
            }
            //if (thisMonster.gameObject.GetComponentInChildren<SpriteRenderer>().sortingOrder < 0)
            //    thisMonster.gameObject.GetComponentInChildren<SpriteRenderer>().sortingOrder *= -1;
        }
        monsterPool[monsterType].Enqueue(thisMonster);
        ++waveNowMonster;
        ShowSkull();
        return thisMonster;
    }
 
    public void EveryMonsterInit()
    {
        for (int i = 0; i < 5++i)
        {
            foreach (GameObject now in monsterPool[i])
            {
                now.GetComponent<MonsterMove>().InitMonster();
                now.SetActive(false);
            }
        }
        waveNowMonster = 0;
        waveMaxType = 1;
        waveMaxMonster = 5;
        waveTerm = 3.0f;
        waveMonsterCount = 0;
        waveWaitTime = 0;
        spawnTime = 0;
        isWaving = false;
        ShowSkull();
    }
}
 
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
//MenuToggleAction.cs
using UnityEngine;
using DG.Tweening;
public class MenuToggleAction : MonoBehaviour
{
    public GameObject optionWindow = null;
    public GameObject SFXBarComponent;
    private OptionBar SFXBar;
    public float maxVol = 1.0f;
    public AudioClip clickSoundSource;
    private AudioSource clickSound;
    public float scaleX, scaleY;
    public int type; // 0 = start, 1 = setting, 2 = exit
    // Use this for initialization
    void Start()
    {
        SFXBarComponent = GameObject.FindGameObjectWithTag("SFXBar");
        SFXBar = SFXBarComponent.GetComponent<OptionBar>();
        clickSound = GetComponent<AudioSource>();
        clickSoundSource = Resources.Load("Sound/menuButtonClick"typeof(AudioClip)) as AudioClip;
    }
 
    // Update is called once per frame
    void Update()
    {
        maxVol = SFXBar.scale;
        clickSound.volume = maxVol;
    }
 
    private void OnMouseDown()
    {
        clickSound.PlayOneShot(clickSoundSource);
        transform.DOScaleX(scaleX - 0.1f, 0.1f);
        transform.DOScaleY(scaleY - 0.1f, 0.1f);
    }
    private void OnMouseUp()
    {
        transform.DOScaleX(scaleX, 0.1f);
        transform.DOScaleY(scaleY, 0.1f);
        switch (type)
        {
            case 0: thisGameInit(); break;
            case 1: OptionToggle(); break;
            case 2: quit(); break;
        }
    }
 
    public void thisGameInit()
    {
        if(optionWindow.transform.position.x < 100)
            OptionToggle();
        GameManager.bGameStart = true;
        TowerManager.instance.EveryTowerInit();
        HomeScript.instance.InitHome();
        MonsterManagerScript.instance.EveryMonsterInit();
        PlayerValue.instance.GameInit();
        PlayerValue.instance.setGold();
        NightScript.instance.NightInit();
    }
 
    void quit()
    {
#if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;
#else
        Application.Quit();
#endif
    }
 
    public void OptionToggle()
    {
        Vector3 nowVec = optionWindow.transform.position;
        if(nowVec.x > 100)
            nowVec.x -= 100;
        else
            nowVec.x += 100;
        optionWindow.transform.position = nowVec;
    }
}
 
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
//MakeTowerButtonScript.cs
using UnityEngine;
 
public class MakeTowerButtonScript : MonoBehaviour
{
    public int type;
    // Use this for initialization
    void Start()
    {
 
    }
 
    // Update is called once per frame
    void Update()
    {
        if (GameManager.bGameStart)
        {
            
        }
    }
 
    private void OnMouseDown()
    {
        if (GameManager.bGameStart)
            CreateTower();
    }
    private void OnMouseEnter()
    {
        TowerManager.instance.onTheBuildBlock = true;
    }
    private void OnMouseExit()
    {
        TowerManager.instance.onTheBuildBlock = false;
    }
 
    public void CreateTower()
    {
        for (int i = 0; i < 5++i)
        {
            if (i == 3)
                continue;
            if (type.Equals(i))
                TowerManager.instance.buildOn(type);
            else
                TowerManager.instance.towerTrans[i].transform.position = new Vector3(1001000);
        }
    }
}
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
//makeTowerBlockScript.cs
using UnityEngine;
 
public class makeTowerBlockScript : MonoBehaviour
{
    public bool halfTransy = true;
    public bool showTowerButton = false;
    public GameObject[] towerButtonsSprite = null;
    public GameObject[] towerButtons = null;
    private bool[] checkShortKeys = new bool[5];
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < 5++i)
        {
            towerButtons[i] = Instantiate(towerButtonsSprite[i]);
            towerButtons[i].SetActive(false);
            checkShortKeys[i] = false;
        }
    }
 
    // Update is called once per frame
    void Update()
    {
        if (halfTransy)
        {
            gameObject.GetComponent<SpriteRenderer>().color = new Color(111, (210.0f / 255.0f));
 
        }
        else
        {
            gameObject.GetComponent<SpriteRenderer>().color = new Color(1111);
        }
 
        if (GameManager.bGameStart)
        {
            if (Input.GetKeyDown(KeyCode.BackQuote))
            {
                showTowerButton = !showTowerButton;
                if (showTowerButton)
                {
                    for (int i = 0; i < 5++i)
                        towerButtons[i].SetActive(true);
                }
                else
                {
                    for (int i = 0; i < 5++i)
                        towerButtons[i].SetActive(false);
                    TowerManager.instance.boolBuilding = false;
                    TowerManager.instance.towerTrans[TowerManager.instance.towerType].transform.position = new Vector3(1001000);
                }
            }
            if (showTowerButton)
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
 
                    towerButtons[0].GetComponent<MakeTowerButtonScript>().CreateTower();
 
                }
                else if (Input.GetKeyDown(KeyCode.Alpha2))
                {
 
                    towerButtons[1].GetComponent<MakeTowerButtonScript>().CreateTower();
                }
                else if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    towerButtons[2].GetComponent<MakeTowerButtonScript>().CreateTower();
                }
                else if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    towerButtons[3].GetComponent<AirplaneCallScript>().callAirplane();
                }
                else if (Input.GetKeyDown(KeyCode.Alpha5))
                {
                    towerButtons[4].GetComponent<MakeTowerButtonScript>().CreateTower();
                }
        }
        else if (showTowerButton)
        {
            showTowerButton = false;
            for (int i = 0; i < 5++i)
                towerButtons[i].SetActive(false);
            TowerManager.instance.boolBuilding = false;
        }
 
    }
 
    private void OnMouseEnter()
    {
        halfTransy = false;
    }
    private void OnMouseExit()
    {
        halfTransy = true;
    }
 
 
    private void OnMouseDown()
    {
        if (!GameManager.bGameStart)
        {
            showTowerButton = false;
            for (int i = 0; i < 5++i)
                towerButtons[i].SetActive(false);
            TowerManager.instance.boolBuilding = false;
        }
        else
        {
            showTowerButton = !showTowerButton;
            if (showTowerButton)
            {
                for (int i = 0; i < 5++i)
                    towerButtons[i].SetActive(true);
            }
            else
            {
                for (int i = 0; i < 5++i)
                    towerButtons[i].SetActive(false);
                TowerManager.instance.boolBuilding = false;
            }
        }
    }
}
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//makePath.cs
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
//세로 0~11번 칸, 가로 0~19번 칸
public class makePath : Singleton<makePath>
{
    //// 우클릭으로 카메라 이동 코드 관련
    //private bool bRButtonDown = false;
    //private Vector2 preMousePos = Vector2.zero;
    //// 여기까지
 
 
    public class MovePath
    {
        public int x = 0;
        public int y = 0;
        public MovePath(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }
    public bool[] routeMap = new bool[240];
 
    public List<MovePath> movePath = new List<MovePath>();
    public bool finishMakePath = false;
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < 240++i)
            routeMap[i] = false;
 
        //나중에 살릴라면 살려야 할 부분
        //for (int i = 0; i < 10; ++i)
        //    AddPath(2, i);
        //for (int i = 3; i < 6; ++i)
        //    AddPath(i, 9);
        //for (int i = 8; i > 1; --i)
        //    AddPath(5, i);
        //for (int i = 6; i < 9; ++i)
        //    AddPath(i, 2);
        //for (int i = 3; i < 9; ++i)
        //    AddPath(8, i);
        //for (int i = 9; i < 14; ++i)
        //    AddPath(i, 8);
        //for (int i = 7; i > 4; --i)
        //    AddPath(13, i);
        //for (int i = 12; i > 10; --i)
        //    AddPath(i, 5);
        //for (int i = 4; i > 1; --i)
        //    AddPath(11, i);
        //for (int i = 12; i < 18; ++i)
        //    AddPath(i, 2);
        //for (int i = 3; i < 8; ++i)
        //    AddPath(17, i);
        //AddPath(16, 7);
        //for (int i = 3; i < 10; ++i)
        //    AddPath(17, i);
        //for (int i = 9; i > 6; --i)
        //    AddPath(16, i);
        LoadJson();
        finishMakePath = true;
        TowerManager.instance.setBuildMap();
        //16,8
        makeTile(161031);
        makeTile(171032);
        makeTile(16933);
        makeTile(17934);
        makeTile(16935);
        makeTile(16835);
        makeTile(17936);
        makeTile(17836);
        makeTile(16837);
        checkTile();
        makeTile(158"rpgTile020"2);// 집 아래 바닥
        makeTile(159"rpgTile020"2);
        makeTile(1510"rpgTile003"2);
        makeTile(1610"rpgTile037"2);
        makeTile(1710"rpgTile037"2);
        makeTile(1810"rpgTile004"2);
        makeTile(188"rpgTile018"2);
        makeTile(189"rpgTile018"2);
 
    }
 
    public void AddPath(int x, int y)
    {
        movePath.Add(new MovePath(x, y));
        routeMap[y * 20 + x] = true;
    }
 
    // Update is called once per frame
    void Update()
    {
        ////우클릭으로 카메라 이동 코드
        //if (Input.GetMouseButtonDown(1))
        //{
        //    bRButtonDown = true;
        //    preMousePos = Input.mousePosition;
        //}
        //if (Input.GetMouseButtonUp(1))
        //{
        //    bRButtonDown = false;
        //}
        //if (bRButtonDown)
        //{
 
        //    Vector2 nowMouseMove = Input.mousePosition;
        //    Vector2 move = preMousePos - nowMouseMove;
        //    preMousePos = nowMouseMove;
        //    Camera.main.transform.Translate(move * 0.015f);
        //}
        ////여기까지
    }
 
 
    public void checkTile()
    {
        for (int i = 0; i < 12++i)
        {
            for (int j = 0; j < 20++j)
            {
                if (routeMap[j + i * 20])
                    makeTile(j, i);
                else if (i != 0 && i != 11 && j != 0 && j != 19)
                {
                    if (routeMap[(j + 1+ i * 20&& routeMap[j + (i - 1* 20])// ┘의 1번 칸
                        makeTile(j, i, 3);
                    else if (routeMap[(j - 1+ i * 20&& routeMap[j + (i - 1* 20])//└의 3번 칸
                        makeTile(j, i, 1);
                    else if (routeMap[(j + 1+ i * 20&& routeMap[j + (i + 1* 20])//┐의 7번 칸
                        makeTile(j, i, 4);
                    else if (routeMap[(j - 1+ i * 20&& routeMap[j + (i + 1* 20])//┌의 9번 칸
                        makeTile(j, i, 2);
                    else if (routeMap[(j + 1+ i * 20])// ㅣ의 왼쪽
                        makeTile(j, i, 11);
                    else if (routeMap[(j - 1+ i * 20])
                        makeTile(j, i, 12);
                    else if (routeMap[j + (i - 1* 20])
                        makeTile(j, i, 13);
                    else if (routeMap[j + (i + 1* 20])
                        makeTile(j, i, 14);
                    else if (routeMap[(j + 1+ (i - 1* 20])
                        makeTile(j, i, 21);
                    else if (routeMap[(j + 1+ (i + 1* 20])
                        makeTile(j, i, 23);
                    else if (routeMap[(j - 1+ (i - 1* 20])
                        makeTile(j, i, 22);
                    else if (routeMap[(j - 1+ (i + 1* 20])
                        makeTile(j, i, 24);
                }
                else
                {
                    if (j.Equals(0&& i > 0 && i < 11)
                    {
                        if (routeMap[j + (i - 1* 20])
                            makeTile(j, i, 1);
                        else if (routeMap[j + (i + 1* 20])
                            makeTile(j, i, 2);
                    }
                    else if (j.Equals(19&& i > 0 && i < 11)
                    {
                        if (routeMap[j + (i - 1* 20])
                            makeTile(j, i, 3);
                        if (routeMap[j + (i + 1* 20])
                            makeTile(j, i, 4);
                    }
 
                    if (i.Equals(11&& j > 0 && j < 19)
                    {
                        if (routeMap[(j - 1+ i * 20])
                            makeTile(j, i, 2);
                        else if (routeMap[(j + 1+ i * 20])
                            makeTile(j, i, 4);
                    }
                    else if (i.Equals(0&& j > 0 && j < 19)
                    {
                        if (routeMap[(j - 1+ i * 20])
                            makeTile(j, i, 1);
                        else if (routeMap[(j + 1+ i * 20])
                            makeTile(j, i, 3);
                    }
 
                }
            }
        }
    }
 
    public void makeTile(int x, int y, int t = 0)
    {
        switch (t)
        {
            case 0: makeTile(x, y, "rpgTile024"); break;//센터
            case 1: makeTile(x, y, "rpgTile036"); break//좌위, 아래우
            case 2: makeTile(x, y, "rpgTile000"); break//좌아래, 위우
            case 3: makeTile(x, y, "rpgTile038"); break//우위, 아래좌
            case 4: makeTile(x, y, "rpgTile002"); break//우아래, 위좌
 
            case 11: makeTile(x, y, "rpgTile020"); break;
            case 12: makeTile(x, y, "rpgTile018"); break;
            case 13: makeTile(x, y, "rpgTile037"); break;
            case 14: makeTile(x, y, "rpgTile001"); break;
 
            case 21: makeTile(x, y, "rpgTile003"); break;
            case 22: makeTile(x, y, "rpgTile004"); break;
            case 23: makeTile(x, y, "rpgTile021"); break;
            case 24: makeTile(x, y, "rpgTile022"); break;
 
            case 31: makeTile(x, y, "rpgTile112"20); break// 지붕 끝 왼쪽
            case 32: makeTile(x, y, "rpgTile113"20); break;
            case 33: makeTile(x, y, "rpgTile148"20); break;
            case 34: makeTile(x, y, "rpgTile149"20); break;
            case 35: makeTile(x, y, "rpgTile083"10); break;
            case 36: makeTile(x, y, "rpgTile085"10); break;
            case 37: makeTile(x, y, "rpgTile189"150.32f); break;
        }
 
    }
 
    public void makeTile(int x, int y, string f, int order = 1float xShift = 0)
    {
        string fileName = "PNG/" + f;
        GameObject gameTile = Resources.Load("TileObject"typeof(GameObject)) as GameObject;
        GameObject instance = Instantiate(gameTile) as GameObject;
        SpriteRenderer pRenderer = instance.AddComponent<SpriteRenderer>();
 
        Sprite tile = Resources.Load(fileName, typeof(Sprite)) as Sprite;
        pRenderer.sprite = tile;
        pRenderer.sortingOrder = order;
        Vector3 pos = new Vector3(x * 0.64f + 0.32f + xShift, y * 0.64f + 0.32f, 0);
        instance.transform.position = pos;
        instance.transform.parent = transform;
    }
 
    private void LoadJson()
    {
        string dir = Application.dataPath + "/PathData.json";
        //String s = System.IO.File.ReadAllText("C:/Users/user/source/repos/defenceTool/defenceTool/bin/Debug/PathData.json");
        String s = System.IO.File.ReadAllText(dir);
        string se = System.Environment.CurrentDirectory + "/Assets/Resources/PathData.json";
 
        JObject root = JObject.Parse(s);
        //JsonObjectCollection root = textParser.Parse(s) as JsonObjectCollection;
        JToken arr = root["Path"];
        JToken arr2 = root["NonPath"];
        foreach (JToken obj in arr)
        {
            double x = obj["X"].Value<double>();
            double y = obj["Y"].Value<double>();
            AddPath((int)x, 10 - (int)y);
        }
        foreach (JToken obj in arr2)
        {
            double x = obj["X"].Value<double>();
            double y = obj["Y"].Value<double>();
            string n = obj["path"].Value<string>().Substring(6010);
            makeTile((int)x, 10 - (int)y, n, 2);
        }
    }
}
 
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
//HPBar.cs
using UnityEngine;
using DG.Tweening;
 
public class HPBar : MonoBehaviour
{
    public GameObject[] HPBarSprite = null;
    public GameObject[] HPBars = null;
    public float hp = 0;
    public float maxHP = 0;
    // Use this for initialization
    void Start()
    {
        //MakeHPBar();
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    public void MakeHPBar()
    {
        for (int i = 0; i < 3++i)
        {
            HPBars[i] = Instantiate(HPBarSprite[i], transform);
        }
        InitHpBarSize();
    }
 
    public void InitHpBarSize()
    {
        HPBars[1].transform.DOScaleX(4.0f, 0);
        HPBars[1].transform.position = new Vector3(transform.position.x, transform.position.y + 0.7f);
        //HPBars[0].transform.position = new Vector3(transform.position.x - 0.086f * 4, transform.position.y + 0.7f);
        //HPBars[2].transform.position = new Vector3(transform.position.x + 0.086f * 4, transform.position.y + 0.7f);
        HPBars[0].transform.position = new Vector3(transform.position.x - 0.0875f * 4, transform.position.y + 0.7f);
        HPBars[2].transform.position = new Vector3(transform.position.x + 0.0875f * 4, transform.position.y + 0.7f);
    }
 
    public void setHpBarSize(float _hp, float _maxHp)
    {
        hp = _hp;
        maxHP = _maxHp;
        float hpPercent = hp / maxHP;
        if (hpPercent < 0)
            hpPercent = 0;
        HPBars[1].transform.DOScaleX(hpPercent * 4.0f, 0);
        //HPBars[0].transform.position = new Vector3(transform.position.x - (0.344f - (1 - hpPercent) * 0.31f), transform.position.y + 0.7f, 0);
        //HPBars[2].transform.position = new Vector3(transform.position.x + (0.344f - (1 - hpPercent) * 0.31f), transform.position.y + 0.7f, 0);
        HPBars[0].transform.position = new Vector3(transform.position.x - (0.349f - (1 - hpPercent) * 0.319f), transform.position.y + 0.7f, 0);
        HPBars[2].transform.position = new Vector3(transform.position.x + (0.349f - (1 - hpPercent) * 0.319f), transform.position.y + 0.7f, 0);
    }
}
 
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
//HomeScript.cs
using UnityEngine;
 
public class HomeScript : Singleton<HomeScript>
{
    public int maxHp;
    public int hp;
    public float gameOverDelayTime = 0;
    public GameObject playButton;
    // Use this for initialization
    void Start()
    {
        //InitHome();
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    public void setHP(int dam)
    {
        hp -= dam;
        if (hp < 0)
        {
            hp = 0;
            TimeManager.bTimeStop = true;
 
                hp = maxHp;
                GameManager.bGameStart = false;
            playButton.GetComponent<PlayButtonScript>().resetButton();
        }
        GetComponent<HPBar>().setHpBarSize(hp, maxHp);
    }
 
    public void InitHome()
    {
        maxHp = 1000;
        hp = 1000;
        GetComponent<HPBar>().MakeHPBar();
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.tag.Contains("monster"))
        {
            foreach(Transform child in collision.transform)
            {
                if (child.gameObject.GetComponent<SpriteRenderer>().sortingOrder < 0)
                    child.gameObject.GetComponent<SpriteRenderer>().sortingOrder *= -1;
            }
        }
    }
}
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
//GameManager.cs
using UnityEngine;
 
public class GameManager : Singleton<GameManager>
{
    public static bool bGameStart = false;
    public GameObject startButton;
    public GameObject settingButton;
    public GameObject exitButton;
    // Use this for initialization
    void Start()
    {
        
    }
 
    // Update is called once per frame
    void Update()
    {
        if(bGameStart)
        {
            if (startButton.activeInHierarchy)
                startButton.SetActive(false);
            if (settingButton.activeInHierarchy)
                settingButton.SetActive(false);
            if (exitButton.activeInHierarchy)
                exitButton.SetActive(false);
        }
        else
        {
            if (!startButton.activeInHierarchy)
                startButton.SetActive(true);
            if (!settingButton.activeInHierarchy)
                settingButton.SetActive(true);
            if (!exitButton.activeInHierarchy)
                exitButton.SetActive(true);
        }
    }
}
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
//EffectManager.cs
using System.Collections.Generic;
using UnityEngine;
 
public class EffectManager : Singleton<EffectManager>
{
    public GameObject[] effectsPrefabs = null;
    private Dictionary<int, Queue<GameObject>> effectPool = new Dictionary<int, Queue<GameObject>>();
    // Use this for initialization
    void Start()
    {
        CreateEffectPool();
    }
    // Update is called once per frame
    void Update()
    {
 
    }
 
    private void CreateEffectPool()
    {
        int tags = 0, maxNum = 200, plus = 0;
        for(int i = 0; i < 4++i)
        {
            if (effectsPrefabs[i].tag.Contains("0"))
                tags = 0;
            if (effectsPrefabs[i].tag.Contains("1"))
                tags = 1;
            if (effectsPrefabs[i].tag.Contains("2"))
                tags = 2;
            if (effectsPrefabs[i].tag.Contains("3"))
                tags = 3;
            if (!effectPool.ContainsKey(tags))
                effectPool.Add(tags, new Queue<GameObject>());
            if (tags == 1)
                plus = 400;
            else
                plus = 0;
            for(int j = 0; j < maxNum + plus; ++j)
            {
                GameObject thisObj = Instantiate(effectsPrefabs[i], new Vector3(1001000), Quaternion.identity, this.transform);
                thisObj.SetActive(false);
                effectPool[tags].Enqueue(thisObj);
            }
        }
    }
 
    public GameObject PopEffectByPool(int effectType, Vector3 pos)
    {
        GameObject thisEffect = effectPool[effectType].Dequeue();
        thisEffect.transform.position = pos;
        thisEffect.SetActive(true);
        //thisEffect.GetComponent<EffectObj>().EffectOn();
        effectPool[effectType].Enqueue(thisEffect);
        return thisEffect;
    }
}
 
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
//deleteButtonScript.cs
using UnityEngine;
 
public class deleteButtonScript : MonoBehaviour
{
    TowerManager TheTowerManager;
    PlayerValue ThePlayerValue;
    // Use this for initialization
    void Start()
    {
        TheTowerManager = TowerManager.instance;
        ThePlayerValue = PlayerValue.instance;
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    private void OnMouseDown()
    {
        int x = TheTowerManager.intClickTowerX;
        int y = TheTowerManager.intClickTowerY;
        int type = TheTowerManager.towerTypeMap[y * 20 + x];
        GameObject nowTower = TheTowerManager.towerObjectMap[y * 20 + x];
        if (x > -1)
        {
            if (50 <= ThePlayerValue.gold)
            {
                if (type.Equals(0))
                {
                    nowTower.GetComponentInChildren<tower>().initTower();
                }
                else if (type.Equals(1))
                {
                    nowTower.GetComponent<tower1>().initTower();
                }
                else if (type.Equals(2))
                {
                    nowTower.GetComponentInChildren<tower2>().initTower();
                }
                nowTower.SetActive(false);
                ThePlayerValue.gold -= 50;
                ThePlayerValue.setGold();
                TheTowerManager.clickPositionInit();
                TheTowerManager.towerTypeMap[y * 20 + x] = -1;
                TheTowerManager.towerObjectMap[y * 20 + x] = null;
                TheTowerManager.buildMap[y * 20 + x] = true;
                TheTowerManager.intClickTowerX = -1;
                TheTowerManager.intClickTowerY = -1;
            }
        }
    }
}
 
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//DataUI.cs
using UnityEngine;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine.UI;
 
public class DataUI : MonoBehaviour
{
    //임마가 매번 좌표 읽어서 보여주는 것으로 하자
    // Use this for initialization
    private string s;
    public GameObject makeTowerBlock;
    public GameObject home;
    public GameObject repairHomeBlock;
    Text t;
    public bool down = false;
    public bool curserHome = false;
    private bool bStart = false;
    void Start()
    {
        //string dir = System.Environment.CurrentDirectory;
        string dir = Application.dataPath;
        print("<-"+dir);
        //s = dir + "/Assets/DataUI.json";
        s = dir + "/DataUI.json";
        FileInfo _finfo = new FileInfo(s);
        if (!_finfo.Exists)
        {
            //JObject root = JObject.Parse(s);
            JObject root = new JObject();
            JArray arr = new JArray();
            //root.Add("tower", arr);
 
            JObject obj = new JObject();
            obj.Add("dam""데미지 : ");
            arr.Add(obj);
            root.Add("tower", arr);
 
            arr = new JArray();
            obj = new JObject();
            obj.Add("name","로켓 런쳐");
            obj.Add("explain""빠르게 로켓을 발사. 스플래시 데미지 보유.");
            arr.Add(obj);
            root.Add("tower0", arr);
 
            arr = new JArray();
            obj = new JObject();
            obj.Add("name""머신 건");
            obj.Add("explain""4발씩 끊어서 총알 발사.");
            arr.Add(obj);
            root.Add("tower1", arr);
 
            arr = new JArray();
            obj = new JObject();
            obj.Add("name""화염 방사기");
            obj.Add("explain""360도 회전하며 불기둥으로 공격");
            arr.Add(obj);
            root.Add("tower2", arr);
 
            arr = new JArray();
            obj = new JObject();
            obj.Add("name""폭격기 호출");
            obj.Add("explain""맵 전역을 폭격, 몰살시킴");
            arr.Add(obj);
            root.Add("tower3", arr);
 
            arr = new JArray();
            obj = new JObject();
            obj.Add("name""폭격기 호출");
            obj.Add("explain""맵 전역을 폭격, 몰살시킴");
            obj.Add("count""잔여 횟수 : ");
            obj.Add("glue""속도 감소 : ");
            arr.Add(obj);
            root.Add("tower4", arr);
 
            arr = new JArray();
            obj = new JObject();
            obj.Add("name""니 집 (수리: HP +50)");
            obj.Add("explain""집 값도 겁나게 비싼데 잃고 나면 늦은기라");
            obj.Add("hp""체력 : ");
            arr.Add(obj);
            root.Add("home", arr);
 
            //System.IO.File.WriteAllText(dir + "/Assets/DataUI.json", root.ToString());
            System.IO.File.WriteAllText(_finfo.FullName, root.ToString());
        }
        s = System.IO.File.ReadAllText(_finfo.FullName);
        print("->" + _finfo.FullName);
        //int a = 10;
        //string ab = "데미지는 \n";
        //string t = "234";
        //int tin = int.Parse(t);
        //string outText = ab + (Random.Range(0, 10) + a).ToString();
        t = GetComponentInChildren<Text>();
        bStart = true;
    }
 
    // Update is called once per frame
    void Update()
    {
        if (bStart == false)
            return;
        /*
         * 봐야 할 순서
         * 1. 오른쪽 끝에 있는가(단추 부분, 있으면 거기서 단추 관련 출력) // y 3이상, x 18이상 <- 마우스 올라가면
         * 2. 집에 있는가(있으면 집 출력) // y 8~10, x = 16~17 <- 마우스 올라가면
         * 3. 그 외에는 타워 클릭 시 출력 // 그 외는 map 참조 <- 클릭 시, 위에 것이 먼저 되어도 마우스가 떼지면 다시 얘가 불려있어야 함
         */
        Vector3 pos = (Input.mousePosition);
        int nowX = (int)pos.x / 64, nowY = (int)pos.y / 64;
 
        //JsonTextParser textParser = new JsonTextParser();
        JObject root = JObject.Parse(s);
        JToken arr;
        JToken obj;
        string showText;
        if (GameManager.bGameStart)
            if (nowX > -1 && nowX < 20 && nowY > -1 && nowY < 11)
            {
                if (pos.x > 1197 && nowY > 2)
                {
                    float _y = pos.y % 100.0f;
                    if (_y >= 8.4f && _y <= 91.6f)
                    {
                        int a = (int)pos.y / 100;
                        if (makeTowerBlock.GetComponent<makeTowerBlockScript>().showTowerButton)
                        {
                            switch ((int)pos.y / 100)
                            {
                                case 6:
                                    arr = root["tower1"];
                                    obj = arr[0];
                                    showText = (obj["name"]).Value<string>() + "\n" + (obj["explain"]).Value<string>();
                                    arr = root["tower"];
                                    obj = arr[0];
                                    showText += "\n" + (obj["dam"]).Value<string>() + " 15";
                                    t.text = showText;
                                    down = true;
                                    curserHome = false;
                                    break;//타워1
                                case 5:
                                    arr = root["tower0"];
                                    obj = arr[0];
                                    showText = (obj["name"]).Value<string>() + "\n" + (obj["explain"]).Value<string>();
                                    arr = root["tower"];
                                    obj = arr[0];
                                    showText += "\n" + (obj["dam"]).Value<string>() + " 50";
                                    t.text = showText;
                                    down = true;
                                    curserHome = false;
                                    break;//타워0
                                case 4:
                                    arr = root["tower2"];
                                    obj = arr[0];
                                    showText = (obj["name"]).Value<string>() + "\n" + (obj["explain"]).Value<string>();
                                    arr = root["tower"];
                                    obj = arr[0];
                                    showText += "\n" + (obj["dam"]).Value<string>() + " 100";
                                    t.text = showText;
                                    down = true;
                                    curserHome = false;
                                    break;//타워2
                                case 3:
                                    arr = root["tower3"];
                                    obj = arr[0];
                                    showText = (obj["name"]).Value<string>() + "\n" + (obj["explain"]).Value<string>();
                                    t.text = showText;
                                    down = true;
                                    curserHome = false;
                                    break;//비행기
                                case 2:
                                    arr = root["tower4"];
                                    obj = arr[0];
                                    showText = (obj["name"]).Value<string>() + "\n" + (obj["explain"]).Value<string>() + "\n" + (obj["glue"]).Value<string>() + " 50%\n" + (obj["count"]).Value<string>() + " 40";
                                    t.text = showText;
                                    down = true;
                                    curserHome = false;
                                    break;//거미줄
                                default://타워 클릭되어 있는지 확인을 넣을 것
                                    nowTowerShow();
                                    break;
                            }
                        }
                        else
                        {//타워 클릭되어 있는지 확인 적을 것
                            nowTowerShow();
                        }
                    }
                }
                else if (nowY > 7 && nowY < 11 && nowX > 15 && nowX < 18)
                {//홈
                    arr = root["home"];
                    obj = arr[0];
                    showText = (obj["name"]).Value<string>() + "\n" + (obj["explain"]).Value<string>() + "\n" + (obj["hp"] ).Value<string>() + " " + home.GetComponent<HomeScript>().hp + " / " + home.GetComponent<HomeScript>().maxHp;
                    t.text = showText;
                    down = true;
                    curserHome = true;
                }
                else if (TowerManager.instance.towerTypeMap[nowY * 20 + nowX].Equals(4))
                {//거미줄 확인
                    GameObject nowWeb = TowerManager.instance.towerObjectMap[nowY * 20 + nowX];
                    arr = root["tower4"];
                    obj = arr[0];
                    int glueCount = nowWeb.GetComponent<SpiderWebScript>().count;
                    string glue = (50 - glueCount).ToString() + "%";
                    showText = (obj["name"] ).Value<string>() + "\n" + (obj["explain"] ).Value<string>() + "\n" + (obj["glue"] ).Value<string>() + " " + glue + "\n" + (obj["count"] ).Value<string>() + " " + (40 - glueCount).ToString();
                    t.text = showText;
                    down = true;
                    curserHome = false;
                }
                else
                {//타워가 클릭되어 있신지 확인
                    nowTowerShow();
                }
            }
            else
            {
                nowTowerShow();
            }
 
        if (down)
        {
            if (transform.position.y > 6.93f)
            {
                Vector3 p = transform.position;
                p.y -= Time.deltaTime * 5.0f;
                transform.position = p;
                if (transform.position.y < 6.93f)
                {
                    p = transform.position;
                    p.y = 6.93f;
                    transform.position = p;
                }
            }
        }
        else
        {
            if (transform.position.y < 8.43f)
            {
                Vector3 p = transform.position;
                p.y += Time.deltaTime * 5.0f;
                transform.position = p;
                if (transform.position.y > 8.43f)
                {
                    p.y = 8.43f;
                    transform.position = p;
                }
            }
        }
 
        if (curserHome)
        {
            if (Input.GetMouseButtonDown(0))
                if (!repairHomeBlock.activeInHierarchy)
                    repairHomeBlock.SetActive(true);
        }
        else
        {
            if (repairHomeBlock.activeInHierarchy)
                if (Input.GetMouseButtonDown(0))
                    repairHomeBlock.SetActive(false);
        }
 
    }
 
    void nowTowerShow()
    {
        int clickX = TowerManager.instance.intClickTowerX;
        if (clickX != -1)
        {
            JObject root = JObject.Parse(s);
            JToken arr;
            JToken obj;
 
            int clickY = TowerManager.instance.intClickTowerY;
            int nowType = TowerManager.instance.towerTypeMap[clickY * 20 + clickX];
            GameObject nowTower = TowerManager.instance.towerObjectMap[clickY * 20 + clickX];
            string showText;
            switch (nowType)
            {
                case 0:
                    arr = root["tower0"];
                    obj = arr[0];
                    showText = (obj["name"] ).Value<string>() + "\n" + (obj["explain"] ).Value<string>();
                    arr = root["tower"];
                    obj = arr[0];
                    showText += "\n" + (obj["dam"] ).Value<string>() + " " + nowTower.GetComponentInChildren<tower>().dam;
                    t.text = showText;
                    down = true;
                    curserHome = false;
                    break;
                case 1:
                    arr = root["tower1"];
                    obj = arr[0];
                    showText = (obj["name"] ).Value<string>() + "\n" + (obj["explain"] ).Value<string>();
                    arr = root["tower"];
                    obj = arr[0];
                    showText += "\n" + (obj["dam"] ).Value<string>() + " " + nowTower.GetComponent<tower1>().dam;
                    t.text = showText;
                    down = true;
                    curserHome = false;
                    break;
                case 2:
                    arr = root["tower2"];
                    obj = arr[0];
                    showText = (obj["name"] ).Value<string>() + "\n" + (obj["explain"] ).Value<string>();
                    arr = root["tower"];
                    obj = arr[0];
                    showText += "\n" + (obj["dam"] ).Value<string>() + " " + nowTower.GetComponentInChildren<tower2>().dam;
                    t.text = showText;
                    down = true;
                    curserHome = false;
                    break;
            }
        }
        else
        {
            t.text = "";
            down = false;
            curserHome = false;
        }
    }
}
 
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
//CFX_AutoDestructShuriken.cs
using UnityEngine;
using System.Collections;
 
[RequireComponent(typeof(ParticleSystem))]
public class CFX_AutoDestructShuriken : MonoBehaviour
{
    public bool OnlyDeactivate;
    
    void OnEnable()
    {
        StartCoroutine("CheckIfAlive");
    }
    
    IEnumerator CheckIfAlive ()
    {
        while(true)
        {
            yield return new WaitForSeconds(0.5f);
            if(!GetComponent<ParticleSystem>().IsAlive(true))
            {
                if(OnlyDeactivate)
                {
                    #if UNITY_3_5
                        this.gameObject.SetActiveRecursively(false);
                    #else
                        this.gameObject.SetActive(false);
                    #endif
                }
                else
                    GameObject.Destroy(this.gameObject);
                break;
            }
        }
    }
}
 
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
//ButtonToggleAction.cs
using UnityEngine;
using DG.Tweening;
 
public class ButtonToggleAction : MonoBehaviour
{
    public GameObject SFXBarComponent;
    private OptionBar SFXBar;
    public float maxVol = 1.0f;
    public AudioClip clickSoundSource;
    private AudioSource clickSound;
    public float scale;
 
    // Use this for initialization
    void Start()
    {
        SFXBarComponent = GameObject.FindGameObjectWithTag("SFXBar");
        SFXBar = SFXBarComponent.GetComponent<OptionBar>();
        clickSound = GetComponent<AudioSource>();
        clickSoundSource = Resources.Load("Sound/smallClick"typeof(AudioClip)) as AudioClip;
    }
 
    // Update is called once per frame
    void Update()
    {
        maxVol = SFXBar.scale;
        clickSound.volume = maxVol;
    }
    private void OnMouseDown()
    {
        clickSound.PlayOneShot(clickSoundSource);
        transform.DOScale(scale-0.1f, 0.1f);
    }
    private void OnMouseUp()
    {
        transform.DOScale(scale, 0.1f);
    }
}
 
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
//buttonShowPrice.cs
using UnityEngine;
/*
 * 타워 0~2는 타입 숫자 그대로
 * 비행기는 타입 3
 * 거미줄은 타입 4
 * 집 수리는 타입 10
 */
public class buttonShowPrice : MonoBehaviour
{
    //public bool isExistTower;
    public GameObject[] num = null;
    public GameObject dollar = null;
    public GameObject[] nowShowPrice = new GameObject[4];
    public GameObject nowDollar = null;
    public int[] nowIntPrice = new int[4];
    public int price;
    public int type;
    // Use this for initialization
    void Start()
    {
        nowDollar = Instantiate(dollar, transform);
        nowDollar.GetComponent<SpriteRenderer>().sortingOrder = 31;
        Vector3 boxVec = transform.position;
        nowDollar.transform.position = boxVec + new Vector3(-0.283f, -0.28f, 0);
        for (int i = 0; i < 4++i)
        {
            nowIntPrice[i] = 0;
            nowShowPrice[i] = Instantiate(num[0], transform);
            nowShowPrice[i].GetComponent<SpriteRenderer>().sortingOrder = 31;
            nowShowPrice[i].transform.position = boxVec + new Vector3(-0.103f + 0.13f * i, -0.28f, 0);
        }
        if (type != -1)
            setPrice();
        else
            setPrice(50);
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    public void setPrice(int _price)
    {
        price = _price;
        setPrice();
    }
    private void setPrice()
    {
        for (int i = 0, j = price, k = 1000; i < 4++i, k /= 10)
        {
            nowIntPrice[i] = j / k;
            j %= k;
            Destroy(nowShowPrice[i]);
            nowShowPrice[i] = Instantiate(num[nowIntPrice[i]], transform);
            nowShowPrice[i].GetComponent<SpriteRenderer>().sortingOrder = 31;
            nowShowPrice[i].transform.position = transform.position + new Vector3(-0.103f + 0.13f * i, -0.28f, 0);
        }
    }
}
 
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
//BulletManager.cs
using System.Collections.Generic;
using UnityEngine;
 
public class BulletManager : Singleton<BulletManager>
{
    public GameObject[] bullet = null;
    private Dictionary<int, Queue<GameObject>> bulletPool = new Dictionary<int, Queue<GameObject>>();
    public int[] bulletKeyValue = null;
    // Use this for initialization
    void Start()
    {
        CreateBulletPool();
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
    public void CreateBulletPool()
    {
        int tags = 0;
        for (int i = 0; i < 1++i)
        {
            if (bullet[i].tag.Contains("0"))
                tags = 0;
 
            bulletKeyValue[i] = tags;
            if (!bulletPool.ContainsKey(bulletKeyValue[i]))
                bulletPool.Add(bulletKeyValue[i], new Queue<GameObject>());
 
            for (int j = 0; j < 240++j)
            {
                GameObject thisObj = Instantiate(bullet[i], new Vector3(1001000), Quaternion.identity, transform);
                thisObj.SetActive(false);
                bulletPool[bulletKeyValue[i]].Enqueue(thisObj);
            }
        }
    }
 
    public GameObject PopBulletByPool(int towerType, Vector3 pos)
    {
        GameObject thisTower = bulletPool[towerType].Dequeue();
        thisTower.transform.position = pos;
        thisTower.SetActive(true);
        bulletPool[towerType].Enqueue(thisTower);
        return thisTower;
    }
    public GameObject PopBulletByPool(int towerType, Vector3 pos, int dam)
    {
        GameObject thisTower = bulletPool[towerType].Dequeue();
        thisTower.GetComponent<rocket>().dam = dam;
        thisTower.transform.position = pos;
        thisTower.SetActive(true);
        bulletPool[towerType].Enqueue(thisTower);
        return thisTower;
    }
}
 
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
//BGMManager.cs
using UnityEngine;
 
public class BGMManager : Singleton<BGMManager>
{
    public GameObject BGMBarComponent = null;
    private OptionBar BGMBar;
    public AudioClip[] BGM = null;
    int BGMMaxNum, nowBGMNum;
    private AudioSource BGMAudio;
    public float maxVol = 1.0f;
    // Use this for initialization
    void Start()
    {
        BGMAudio = GetComponent<AudioSource>();
        BGMBar = BGMBarComponent.GetComponent<OptionBar>();
        BGMMaxNum = BGM.Length;
        nowBGMNum = 0;
    }
 
    // Update is called once per frame
    void Update()
    {
        maxVol = BGMBar.scale;
        if (!BGMAudio.isPlaying)
        {
            BGMAudio.PlayOneShot(BGM[nowBGMNum++], 1);
            BGMAudio.volume = 0;
            nowBGMNum %= BGMMaxNum;
        }
        else if (BGMAudio.volume < maxVol)
        {
            BGMAudio.volume = BGMAudio.volume + 0.01f;
        }
        else if (BGMAudio.volume > maxVol)
            BGMAudio.volume = maxVol;
    }
}
 
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
//AtkCircleScript.cs
using UnityEngine;
using DG.Tweening;
 
public class AtkCircleScript : MonoBehaviour
{
    public float firstScale;
    private float day;
    private float night;
    // Use this for initialization
    void Start()
    {
        day = firstScale;
        night = firstScale * 2.2f / 3.0f;
    }
 
    // Update is called once per frame
    void Update()
    {
        if(NightScript.instance.isNight)
        {
            transform.DOScale(night, 0);
        }
        else
        {
            transform.DOScale(day, 0);
        }
    }
}
 
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
//AirplaneMove.cs
using UnityEngine;
 
public class AirplaneMove : Singleton<AirplaneMove>
{
    public GameObject SFXBarComponent;
    private OptionBar SFXBar;
    public float maxVol = 1.0f;
    public AudioClip bombSoundSource;
    private AudioSource bombSound;
    public bool boolRequest;
    private bool[] effect = new bool[6];
    private EffectManager TheEffectManager;
    // Use this for initialization
    void Start()
    {
        SFXBarComponent = GameObject.FindGameObjectWithTag("SFXBar");
        SFXBar = SFXBarComponent.GetComponent<OptionBar>();
        TheEffectManager = EffectManager.instance;
        bombSound = GetComponent<AudioSource>();
        bombSoundSource = Resources.Load("Sound/bn11"typeof(AudioClip)) as AudioClip;
        boolRequest = false;
        for (int i = 0; i < 6++i)
            effect[i] = false;
    }
 
    // Update is called once per frame
    void Update()
    {
        maxVol = SFXBar.scale;
        bombSound.volume = maxVol;
        if (boolRequest)
        {
            Vector3 pos = transform.position;
            pos.x += TimeManager.GameTime * 6.0f;
            transform.position = pos;
            if (!effect[0])
            {
                if (pos.x > 1)
                {
                    effect[0= true;
                    TheEffectManager.PopEffectByPool(3new Vector3(140));
                    bombSound.PlayOneShot(bombSoundSource);
                }
            }
            else if(!effect[1])
            {
                if(pos.x > 3)
                {
                    effect[1= true;
                    TheEffectManager.PopEffectByPool(3new Vector3(30.5f, 0));
                }
            }
            else if (!effect[2])
            {
                if (pos.x > 5)
                {
                    effect[2= true;
                    TheEffectManager.PopEffectByPool(3new Vector3(530));
                }
            }
            else if (!effect[3])
            {
                if (pos.x > 7)
                {
                    effect[3= true;
                    TheEffectManager.PopEffectByPool(3new Vector3(710));
                    bombSound.PlayOneShot(bombSoundSource);
                }
            }
            else if (!effect[4])
            {
                if (pos.x > 9)
                {
                    effect[4= true;
                    TheEffectManager.PopEffectByPool(3new Vector3(900));
                }
            }
            else if (!effect[5])
            {
                if (pos.x > 11)
                {
                    effect[5= true;
                    TheEffectManager.PopEffectByPool(3new Vector3(1130));
                    bombSound.PlayOneShot(bombSoundSource);
                }
            }
        }
        if (transform.position.x >= 16.8f)
        {
            transform.position = new Vector3(-3.2f, 3.84f, 0);
            boolRequest = false;
            for (int i = 0; i < 6++i)
                effect[i] = false;
        }
    }
 
    public void OnRequest()
    {
        boolRequest = true;
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag.Contains("monster"))
        {
            //collision.GetComponent<MonsterMove>().hp -= 10000;
            collision.GetComponent<MonsterMove>().setHP(10000);
        }
    }
}
 
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
//AirplaneCallScript.cs
using UnityEngine;
 
public class AirplaneCallScript : MonoBehaviour
{
    public GameObject airplane;
    // Use this for initialization
    void Start()
    {
        airplane = GameObject.FindGameObjectWithTag("airplane");
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
    private void OnMouseDown()
    {
        callAirplane();
    }
    public void callAirplane()
    {
        if (PlayerValue.instance.gold >= 9999)
        {
            if (!airplane.GetComponent<AirplaneMove>().boolRequest)
            {
                airplane.GetComponent<AirplaneMove>().OnRequest();
 
                PlayerValue.instance.gold -= 9999;
                PlayerValue.instance.setGold();
            }
        }
    }
}
 
cs


//DataUI.Json

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
{
    "tower"[
        {
            "dam""데미지 : "
        }
    ],
    "tower0"[
        {
            "name""로켓 런쳐",
            "explain""빠르게 로켓을 발사. 스플래시 데미지 보유."
        }
    ],
    "tower1"[
        {
            "name""머신 건",
            "explain""4발씩 끊어서 총알 발사."
        }
    ],
    "tower2"[
        {
            "name""화염 방사기",
            "explain""360도 회전하며 불기둥으로 공격"
        }
    ],
    "tower3"[
        {
            "name""폭격기 호출",
            "explain""맵 전역을 폭격, 몰살시킴"
        }
    ],
    "tower4"[
        {
            "name""거미줄",
            "explain""적들의 속도를 감소",
            "count""잔여 횟수 : ",
            "glue""속도 감소 : "
        }
    ],
    "home"[
        {
            "name""니 집 (수리: HP +50)",
            "explain""집 값도 겁나게 비싼데 잃고 나면 늦은기라",
            "hp""체력 : "
        }
    ]
}
cs



===========================

'BCA > 4. Unity' 카테고리의 다른 글

35. Terrain, nav mash  (0) 2018.05.10
34. 3D plane에서 cube 이동  (0) 2018.05.09
31. 연출용 툴 이용해 유니티에서 연출  (0) 2018.04.27
29. 테트리스  (0) 2018.04.04
28. 슈팅게임 일단은 완성  (0) 2018.03.30
Comments