VioletaBabel

28. 슈팅게임 일단은 완성 본문

BCA/4. Unity
28. 슈팅게임 일단은 완성
Beabletoet 2018. 3. 30. 17:23
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
//UFO.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class UFO : MonoBehaviour
{
    private GameManager TheGameManager;
    private BulletManager TheBulletManager;
    private ItemManager TheItemManager;
    private ScoreManager TheScoreManager;
    private Bomb TheBombManager;
    private EffectManager TheEffectManager;
 
    public GameObject player = null;
 
 
    public AudioClip LaserSound;
    public AudioClip bombSound;
    AudioSource myAudio;
 
    float preShootTime = 0.3f;
    float shootTime = 1.0f;
    public float MaxHP = 100.0f;
    public float HP = 100.0f;
    public int pattern = 0// 패턴0 : 
 
    //패턴1에 사용하는 변수들
    private float sinTime = 0;
    private int sCurveType = 1;
    private float straightTime = 0;
 
    //패턴 1,2, 보스에 사용하는 변수
    private float plusOrminus = 1;
 
    //패턴 3, 보스에 사용하는 변수
    private int shotPt = 0;
 
    //보스 패턴 변수
    private bool relayShot = false;
    private float nowShotAngle = -1.5f;
 
 
    //플레이어 폭탄 락온용
    public GameObject BombCrossHair = null;
 
    //private Vector2[] movePos = new Vector2[6]; // 패턴을 가지고 움직이게 할 것.
    private int nowState = 0;
    void Start()
    {
        TheGameManager = GameManager.Instance;
        TheBulletManager = BulletManager.Instance;
        TheItemManager = ItemManager.Instance;
        TheScoreManager = ScoreManager.Instance;
        TheBombManager = Bomb.Instance;
        TheEffectManager = EffectManager.Instance;
        myAudio = GetComponent<AudioSource>();
        Transform ts = GetComponent<Transform>();
 
        //for (int i = 0; i < 5; ++i)
        //{
        //    float rx = Random.Range(-4.0f, 4.0f);
        //    float ry = Random.Range(0, 5.0f) - (float)i;
        //    movePos[i] = new Vector2(rx, ry);
        //}
        //movePos[5] = new Vector2(movePos[4].x, 4.0f);
        //transform.DOMove(movePos[0], 2.0f);
 
        switch (pattern)
        {
            case 0: HP = 40; MaxHP = HP; break;
            case 1: HP = 40; MaxHP = HP; break;
            case 2: HP = 400; MaxHP = HP; break;
            case 3: HP = 800; MaxHP = HP; break;
            case 4: HP = 3000; MaxHP = HP; break;
        }
    }
 
 
 
 
    void Update()
    {
        if (TheGameManager.gameOn)
        {
            //if (TheGameManager.boolInGame)
            //{
            //    if (TheGameManager.nonDeadTime <= 0)
            //    {
            //        preShootTime += TimeManager.GameTime;
            //        if (preShootTime >= shootTime)
            //        {
 
            //            TheBulletManager.PopBulletByPool(0, transform.position);
            //            preShootTime -= shootTime;
            //        }
            //    }
            //}
            //if (Vector2.Distance(movePos[nowState], transform.position) < 0.1f)
            //{
            //    if (nowState < 5)
            //    {
            //        ++nowState;
            //        transform.DOMove(movePos[nowState], 2.0f);
            //    }
            //    else
            //    {
            //        //Destroy(transform.gameObject);
            //    }
            //}
            if (!TheBombManager.bombSwitch && !TheBombManager.bombMove)
            {
                switch (pattern)
                {
                    case 0: Pt0Move(); break;
                    case 1: plusOrminus = transform.position.x; Pt1Move(); break;
                    case 2: Pt2Move(); break;
                    case 3: Pt3Move(); break;
                    case 4: Pt4Move(); break;
                }
            }
        }
        if (this.transform.position.y <= -5.5f)
        {
            this.gameObject.SetActive(false);
            HP = MaxHP;
            this.GetComponent<HPBar>().setHpBarSize(HP, MaxHP, 0);
        }
    }
    public void PlaySound()
    {
        myAudio.PlayOneShot(LaserSound);
    }
    public void PlaySound(AudioClip a)
    {
        myAudio.PlayOneShot(a);
    }
    private void Pt0Move()
    {
        transform.position = new Vector2(transform.position.x, transform.position.y - (TimeManager.GameTime * 2.0f));
    }
 
    private void Pt1Move()
    {
        if (transform.position.y < 4)
        {
            float z = Mathf.Sin(sinTime * 2* 90;
            Quaternion q = new Quaternion();
            q.eulerAngles = new Vector3(00, z);
            transform.rotation = q;
            sinTime += TimeManager.GameTime;
            if (TheGameManager.boolInGame)
                if (TheGameManager.nonDeadTime <= 0)
                {
                    preShootTime += TimeManager.GameTime;
                    if (preShootTime >= 1.0f)
                    {
                        PlaySound();
                        TheBulletManager.PopBulletByPool(0, transform.position);
                        preShootTime -= 1.0f;
                    }
                }
        }
        transform.Translate(Vector3.down * TimeManager.GameTime * 3);
    }
 
    private void Pt2Move()
    {
        if (transform.position.y > 4)
            transform.position = new Vector2(transform.position.x, transform.position.y - (TimeManager.GameTime * 2.0f));
        else
        {
            if (transform.position.x <= -4 || transform.position.x >= 4)
            {
                plusOrminus *= -1;
            }
 
 
            if (TheGameManager.boolInGame)
                if (TheGameManager.nonDeadTime <= 0)
                {
                    preShootTime += TimeManager.GameTime;
                    if (preShootTime >= 1.0f)
                    {
                        PlaySound();
                        TheBulletManager.PopBulletByPool(4, transform.position, new Vector2(-1-1).normalized);
                        TheBulletManager.PopBulletByPool(4, transform.position, new Vector2(-0.5f, -1).normalized);
                        TheBulletManager.PopBulletByPool(4, transform.position, new Vector2(0-1).normalized);
                        TheBulletManager.PopBulletByPool(4, transform.position, new Vector2(1-1).normalized);
                        TheBulletManager.PopBulletByPool(4, transform.position, new Vector2(0.5f, -1).normalized);
                        preShootTime -= 1.0f;
                    }
                }
 
            transform.position = new Vector2(transform.position.x + plusOrminus * 2 * TimeManager.GameTime, transform.position.y);
        }
    }
 
    private void Pt3Move()
    {
        if (transform.position.y > 4)
            transform.position = new Vector2(transform.position.x, transform.position.y - (TimeManager.GameTime * 2.0f));
        else
        {
            if (TheGameManager.boolInGame)
                if (TheGameManager.nonDeadTime <= 0)
                {
                    preShootTime += TimeManager.GameTime;
 
                    if (preShootTime >= 1.0f)
                    {
                        switch (shotPt)
                        {
                            case 0:
                                Pt3_1Wave();
                                break;
                            case 1:
                                Pt3_2wave();
                                break;
                            case 2:
                                Pt3_3wave();
                                break;
                            case 3:
                                Pt3_2wave();
                                break;
                            case 4:
                                Pt3_3wave();
                                break;
                            case 5:
                                Pt3_1Wave();
                                break;
                            case 6:
                                Pt3_4wave();
                                break;
                        }
                        preShootTime -= 1.0f;
                        shotPt = (shotPt + 1) % 8;
                    }
                }
        }
    }
 
 
    private void Pt3_1Wave()
    {// 7발 이뿌게 퍼지도록
        PlaySound();
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(-1.5f, -1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(-1-1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(4, transform.position, new Vector2(-0.5f, -1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(0-1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(4, transform.position, new Vector2(0.5f, -1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(1-1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(1.5f, -1).normalized, 0.15f);
    }
 
    private void Pt3_2wave()
    {//4발 작은거, 각도 랜덤
        float f;
        PlaySound();
        for (int i = 0; i < 4++i)
        {
            f = Random.Range(-1.0f, 1.0f);
            TheBulletManager.PopBulletByPool(4, transform.position, new Vector2(f, -1).normalized, 0.15f);
        }
        
    }
 
    private void Pt3_3wave()
    {//3발 큰거, 각도 랜덤, 더 빠름
        float f;
        PlaySound();
        for (int i = 0; i < 4++i)
        {
            f = Random.Range(-1.0f, 1.0f);
            TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(f, -1).normalized, 0.2f);
        }
    }
 
    private void Pt3_4wave()
    {//6발 큰거 이뿌게 퍼지도록
        PlaySound();
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(-1.25f, -1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(-0.75f, -1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(-0.25f, -1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(0.75f, -1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(0.25f, -1).normalized, 0.15f);
        TheBulletManager.PopBulletByPool(5, transform.position, new Vector2(1.25f, -1).normalized, 0.15f);
    }
 
    private void Pt4Move()
    {
        if (transform.position.y > 2.5f)
            transform.position = new Vector2(transform.position.x, transform.position.y - (TimeManager.GameTime * 2.0f));
        else
        {
            if (TheGameManager.boolInGame)
                if (TheGameManager.nonDeadTime <= 0)
                {
                    preShootTime += TimeManager.GameTime;
 
                    if (!relayShot)
                    {
                        if (preShootTime >= 2.0f)
                        {
                            switch (shotPt)
                            {
                                case 0:
                                    Pt4_1Wave();
                                    break;
                                case 1:
                                    Pt4_2wave();
                                    break;
                                case 2:
                                    Pt4_3wave(-0.1f);
                                    break;
                                case 3:
                                    Pt4_3wave();
                                    break;
                                case 4:
                                    Pt4_3wave(0.1f);
                                    relayShot = true;
                                    break;
                            }
                            preShootTime -= 2.0f;
                            shotPt = (shotPt + 1) % 6;
                        }
                    }
                    else
                    {
                        if(preShootTime >= 0.2f)
                        {
                            PlaySound();
                            TheBulletManager.PopBulletByPool(7, transform.position, new Vector2(nowShotAngle, -1).normalized, 0.3f);
                            if (nowShotAngle > 1.5f)
                            {
                                plusOrminus *= -1;
                            }
                            else if (nowShotAngle < -1.5f)
                            {
                                plusOrminus *= -1;
                                relayShot = false;
                            }
                            nowShotAngle += plusOrminus * 0.2f;
                        }
                    }
                }
        }
    }
 
    private void Pt4_1Wave()
    {// 7발 이뿌게 퍼지도록
        float r = Random.Range(-0.5f, 0.5f);
        for (int i = 0; i < 7++i)
        {
            PlaySound();
            TheBulletManager.PopBulletByPool(6, transform.position, new Vector2(-1.5f + 0.5f * i + r, -1).normalized, 0.2f);
        }
    }
 
    private void Pt4_2wave()
    {//6발 큰거 이뿌게 퍼지도록
        float r = Random.Range(-0.5f, 0.5f);
        for (int i = 0; i < 7++i)
        {
            PlaySound();
            TheBulletManager.PopBulletByPool(6, transform.position, new Vector2(-1.25f + 0.5f * i + r, -1).normalized, 0.2f);
        }
    }
 
    private void Pt4_3wave(float r = 0)
    {
        for (int i = 0; i < 15++i)
        {
            PlaySound();
            TheBulletManager.PopBulletByPool(7, transform.position, new Vector2(-1.5f + 0.2f * i+r, -1).normalized, 0.25f);
        }
    }
 
    public void PlayerHit(int dam)
    {
        HP -= dam;
        this.GetComponent<HPBar>().setHpBarSize(HP, MaxHP, dam);
 
        if (HP <= 0 && gameObject.transform.position.x != 100)
        {
            PlaySound(bombSound);
            switch (pattern)
            {   
                case 4: TheEffectManager.PopEffectByPool(0this.transform.position);break;
                case 3: TheEffectManager.PopEffectByPool(4this.transform.position);break;
                default: TheEffectManager.PopEffectByPool(3this.transform.position);break;
            }
            TheScoreManager.ScoreUp(10);
            HP = 0;
            gameObject.SetActive(false);
            HP = MaxHP;
            this.GetComponent<HPBar>().InitHPBarSize();
            this.GetComponent<HPBar>().setHpBarSize(HP, MaxHP, 0);
            
            int a = Random.Range(05);
            if (a.Equals(0))
            {
                a = Random.Range(02); // 아이템 지금은 2개. 나중에 수정
                TheItemManager.PopItemByPool(a, this.transform.position);
            }
            gameObject.transform.position = new Vector2(100100);
        }
    }
 
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name.Contains("playerShip"))
        {
            if (TheGameManager.nonDeadTime <= 0)
            {
                //gameObject.SetActive(false);
                if (collision.GetComponent<Shield>().getShield().Equals(-1))
                {
                    TheItemManager.PopItemByPool(0this.transform.position);
                    TheItemManager.PopItemByPool(1this.transform.position);
                    TheEffectManager.PopEffectByPool(3this.transform.position);
                    collision.gameObject.SetActive(false);
                    TheGameManager.boolInGame = false;
                    collision.GetComponent<PlayerLaser>().InitPower();
                }
                else
                    collision.GetComponent<Shield>().minusShield();
            }
        }
    }
}
 
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
//TimeManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TimeManager : MonoBehaviour
{
 
    static public float GameTime = 0;
    static public bool bTimeStop = false;
    // 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
//Singleton.cs
using System.Collections;
using System.Collections.Generic;
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
//ShieldItem.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ShieldItem : MonoBehaviour
{
    public AudioClip shieldUpSound;
    AudioSource myAudio;
    // Use this for initialization
    void Start ()
    {
        myAudio = GetComponent<AudioSource>();
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    public void PlaySound(AudioClip a)
    {
        myAudio.PlayOneShot(a);
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name.Contains("playerShip"))
        {
            PlaySound(shieldUpSound);
            this.gameObject.SetActive(false);
            collision.GetComponent<Shield>().fullShield();
        }
    }
}
 
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
//Shield.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Shield : MonoBehaviour
{
    public GameObject[] shield = new GameObject[3];
    public GameObject[] playerShield = new GameObject[3];
    private int nowShield = -1;
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < 3++i)
        {
            playerShield[i] = Instantiate(shield[i], transform);
        }    
        changeShield();
    }
 
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    public void minusShield()
    {
        if (nowShield > -1)
            --nowShield;
        changeShield();
    }
 
    public int getShield()
    {
        return nowShield;
    }
    private void changeShield()
    {
        for (int i = 0; i < 3++i)
            playerShield[i].SetActive(false);
        if (nowShield > -1)
            playerShield[nowShield].SetActive(true);
    }
    public void fullShield()
    {
        nowShield = 2;
        changeShield();
    }
}
 
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
//ScoreManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ScoreManager : Singleton<ScoreManager>
{
    private Dictionary<int, Queue<GameObject>> scorePool = new Dictionary<int, Queue<GameObject>>();
    public int score = 0;
    public GameObject[] ScoreImage = null;
    public GameObject[] NowScore = null;
    // Use this for initialization
    void Start ()
    {
        CreateScorePool();
    }
    
    // Update is called once per frame
    void Update ()
    {
        
    }
    public void ScoreZero()
    {
        score = 0;
        ChangeScore();
    }
    public void ScoreUp(int val)
    {
        score += val;
        ChangeScore();
    }
    public void ChangeScore()
    {
        if (NowScore[0== null)
        {
            for(int i = 0; i < 5++i)
            {
                NowScore[i] = PopScoreByPool(i, 0);
            }
        }
        else
        {
            int[] intNowScore = new int[5];
            for (int i = 10000, j = score, k = 0; i > 0; i /= 10++k)
            {
                intNowScore[k] = j / i;
                j %= i;
            }
            for (int i = 0; i < 5++i)
            {
                NowScore[i].SetActive(false);
                NowScore[i] = PopScoreByPool(i, intNowScore[i]);
            }
        }
    }
 
    public void ScoreOff()
    {
        for (int i = 0; i < 5++i)
        {
            NowScore[i].SetActive(false);
            score = 0;
        }
    }
 
    public void CreateScorePool()
    {
        for(int i = 0; i < 10++i)
        {
            if(!scorePool.ContainsKey(i))
            {
                scorePool.Add(i, new Queue<GameObject>());
            }
            for(int j = 0; j < 5++j)
            {
                GameObject thisObj = Instantiate(ScoreImage[i], new Vector3(1001000), Quaternion.identity);
                thisObj.SetActive(false);
                thisObj.transform.parent = this.transform;
                scorePool[i].Enqueue(thisObj);
            }
        }
    }
    public GameObject PopScoreByPool(int ScoreType, int val)
    {
        GameObject thisScore = scorePool[val].Dequeue();
        thisScore.transform.position = new Vector2(4.05f + 0.2f * ScoreType, 4.85f);
        thisScore.SetActive(true);
        scorePool[val].Enqueue(thisScore);
        return thisScore;
    }
}
 
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
//PowerUpItem.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PowerUpItem : MonoBehaviour
{
    public AudioClip powerUpSound;
    AudioSource myAudio;
    // Use this for initialization
    void Start()
    {
        myAudio = GetComponent<AudioSource>();
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
    public void PlaySound(AudioClip a)
    {
        myAudio.PlayOneShot(a);
    }
 
 
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name.Contains("playerShip"))
        {
            PlaySound(powerUpSound);
            this.gameObject.SetActive(false);
            collision.GetComponent<PlayerLaser>().PowerUp();
        }
    }
 
}
 
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
//PlayerShip.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlayerShip : MonoBehaviour
{
    private GameManager TheGameManager;
    public GameObject TheBombLine = null;
 
    public AudioClip playerLaserSound = null;
    AudioSource myAudio;
    // Use this for initialization
    void Start ()
    {
        myAudio = GetComponent<AudioSource>();
        TheGameManager = GameManager.Instance;
    }
    
    // Update is called once per frame
    void Update ()
    {
        if (TheGameManager.gameOn)
        {
            //Vector2 mousePos = Input.mousePosition;
            //mousePos = Camera.main.ScreenToWorldPoint(mousePos);
            //Vector2 myPos = transform.position;
            //Vector2 dir = mousePos - myPos;
            //dir.Normalize();
            //float angle = Vector2.SignedAngle(Vector2.up, dir);
            //Quaternion q = (new Quaternion());
            //q.eulerAngles = new Vector3(0, 0, angle);
            //transform.rotation = q;
            //이건 마우스 따라가는 코드이니 지우지말고 나중에 써먹자
 
            if (TheGameManager.nonDeadTime-1 > 0)
                return;//부활하면 1초간 움직임 불가
 
            if(Input.GetKeyDown(KeyCode.Q))
            {
                TheGameManager.cheatOn = !TheGameManager.cheatOn;
            }
            if (Input.GetKeyDown(KeyCode.LeftControl))
            {
                GetComponent<PlayerLaser>().shoot(true);
            }
            else if (Input.GetKeyUp(KeyCode.LeftControl))
            {
                GetComponent<PlayerLaser>().shoot(false);
            }
            if(Input.GetKeyDown(KeyCode.LeftShift))
            {
                TheBombLine.GetComponent<Bomb>().BombOn();
            }
 
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                if (transform.position.x > -5.0f)
                    transform.Translate(-TimeManager.GameTime * 10.0f, 00);
            }
            else if (Input.GetKey(KeyCode.RightArrow))
            {
                if (transform.position.x < 5.0f)
                    transform.Translate(TimeManager.GameTime * 10.0f, 00);
            }
 
            if (Input.GetKey(KeyCode.DownArrow))
            {
                if (transform.position.y > -5.0f)
                    transform.Translate(0-TimeManager.GameTime * 10.0f, 0);
            }
            else if (Input.GetKey(KeyCode.UpArrow))
            {
                if (transform.position.y < 5.0f)
                    transform.Translate(0, TimeManager.GameTime * 10.0f, 0);
            }
        }
    }
    public void PlaySound()
    {
        myAudio.PlayOneShot(playerLaserSound);
    }
}
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
//PlayerRocket.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlayerRocket : MonoBehaviour
{
    EffectManager TheEffectManager;
    private const int rocketDam = 20;
    public GameObject closeEnemy = null;
    public Vector2 dir = Vector2.zero;
    // Use this for initialization
    void Start()
    {
        GetComponent<Rigidbody2D>().AddForce(new Vector2(030.0f));
    }
 
    // Update is called once per frame
    void Update()
    {
        if (closeEnemy == null)
        {
            transform.Translate(Vector2.up * 20.0f * TimeManager.GameTime);
        }
        else
        {
            Quaternion q = new Quaternion();
            if (closeEnemy.activeInHierarchy)
            {
                dir = closeEnemy.transform.position - transform.position;
                dir.Normalize();
                Vector3 a = new Vector3(00, Vector3.Angle(Vector3.up, dir));
                if (dir.x > 0)
                    a *= -1;
                q.eulerAngles = a;
                transform.rotation = q;
            }
            transform.Translate(dir * 20.0f * TimeManager.GameTime);
            if (dir.Equals(Vector2.zero))
                gameObject.SetActive(false);
        }
        Vector2 nowPos = transform.position;
        if (nowPos.x < -6.0f || nowPos.x > 6.0f || nowPos.y < -6.0f || nowPos.y > 6.0f)
            gameObject.SetActive(false);
    }
 
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name.Contains("wing"))
        {
            gameObject.SetActive(false);
            //collision.gameObject.SetActive(false);
            var col = collision.GetComponent<BossParts>();
            col.PlayerHit(rocketDam);
        }
        else if(collision.name.Contains("Boss"))
        {
            gameObject.SetActive(false);
            var col = collision.GetComponent<UFO>();
            col.PlayerHit(rocketDam);
        }
        else if (collision.name.Contains("enemy"))
        {
            gameObject.SetActive(false);
            var col = collision.GetComponent<UFO>();
            col.PlayerHit(rocketDam);
        }
    }
}
 
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
//PlayerLaser.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlayerLaser : MonoBehaviour
{
    public GameObject laser1 = null;
    public GameObject laser2 = null;
    public GameObject rocket = null;
    public GameObject closeEnemy = null;
    private bool bShoot = false;
    private int nowPower = 3;//레이저의 파워
    private float shootTime = 0.15f/4;//몇 초에 한 발 나가는가
    private float preShootTime = 0.15f/4// 이전에 쐈던 시간
    private int countShotForRocket = 0;
    private BulletManager TheBulletManager;
    private GaugeManager TheGaugeManager;
 
    public AudioClip playerLaserSound = null;
    AudioSource myAudio;
    private float audioTime = 0.1f;
 
    void Start()
    {
        TheBulletManager = BulletManager.Instance;
        TheBulletManager.CreateBulletPool();
        TheGaugeManager = GaugeManager.Instance;
        myAudio = GetComponent<AudioSource>();
    }
 
    void Update()
    {
        if (bShoot)
        {
            ShootingType();
            audioTime += TimeManager.GameTime;
            if (audioTime >= 0.1f)
            {
                audioTime -= 0.1f;
                PlaySound();
            }
        }
    }
 
    public int GetNowPower()
    {
        return nowPower;
    }
 
    public void shoot(bool bShootButton)
    {
        bShoot = bShootButton;
        if (!bShoot)
        {
            preShootTime = shootTime;
            audioTime = 0.1f;
        }
    }
    public void PowerUp()
    {
        if (nowPower < 3)
        {
            ++nowPower;
            //shootTime = (float)(4 - nowPower) * 0.075f; // 파워가 오를 때마다 쏘는 속도가 조금씩 감소
        }
        //else
        //    TheGaugeManager.GaugeMaxUp();
        if (nowPower.Equals(3))
        {
            TheGaugeManager.GaugeMaxUp();
        }
        else
        {
            TheGaugeManager.OffGauge();
        }
    }
    public void InitPower()
    {
        nowPower = 1;
        TheGaugeManager.OffGauge();
    }
    public void ShootingType()
    {
        preShootTime += TimeManager.GameTime;
        if (preShootTime >= shootTime)
        {
            TheBulletManager.PopBulletByPool(1, transform.position);
            preShootTime -= shootTime;
            
            if (nowPower > 1)
            {
                Vector2 laser1Pos = transform.position;
                Vector2 laser2Pos = transform.position;
                laser1Pos.x -= 0.2f;
                laser2Pos.x += 0.2f;
                TheBulletManager.PopBulletByPool(2, laser1Pos);
                TheBulletManager.PopBulletByPool(2, laser2Pos);
                countShotForRocket = (countShotForRocket + 1) % 8;
            }
            if (nowPower > 2 && countShotForRocket.Equals(0)&&(TheGaugeManager.GetNowGauge() > 0))
            {
                TheGaugeManager.MinusGauge();
                GameObject rockets = TheBulletManager.PopBulletByPool(3, transform.position);
                PlayerRocket roc = rockets.GetComponent<PlayerRocket>();
                roc.closeEnemy = closeEnemy;
                preShootTime = 0;
            }
        }
    }
    public void PlaySound()
    {
        myAudio.PlayOneShot(playerLaserSound);
    }
}
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
//MoveItem.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class MoveItem : MonoBehaviour
{
    public Vector2 nowArrow;
    public int count = 0;
    // Use this for initialization
    void Start ()
    {
        nowArrow = new Vector2(Random.Range(0360.0f), Random.Range(0360.0f));
        nowArrow.Normalize();
    }
    
    // Update is called once per frame
    void Update ()
    {
        if (count != 3)
        {
            if (transform.position.x > 5.0f || transform.position.x < -5.0f)
            {
                float x = (transform.position.x > 0) ? 4.99f : -4.99f;
                transform.position = new Vector2(x, transform.position.y);
                nowArrow.x *= -1;
                ++count;
                nowArrow.Normalize();
            }
            else if (transform.position.y > 5.0f || transform.position.y < -5.0f)
            {
                float y = (transform.position.y > 0) ? 4.99f : -4.99f;
                transform.position = new Vector2(transform.position.x, y);
                nowArrow.y *= -1;
                ++count;
                nowArrow.Normalize();
            }
            transform.Translate(nowArrow * TimeManager.GameTime);
        }
        else
        {
            transform.Translate(nowArrow * TimeManager.GameTime);
            if (transform.position.x > 6.0f || transform.position.x < -6.0f || transform.position.y > 6.0f || transform.position.y < -6.0f)
                gameObject.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
44
45
46
47
48
49
50
//Laser.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Laser : MonoBehaviour
{
    
    private const int laserDam = 2;
    // Use this for initialization
    void Start()
    {
 
    }
 
    // Update is called once per frame
    void Update()
    {
        transform.Translate(new Vector2(01.0f) * TimeManager.GameTime * 20.0f);
        Vector2 nowPos = transform.position;
        if (nowPos.x < -5.0f || nowPos.x > 5.0f || nowPos.y < -5.5f || nowPos.y > 5.0f)
            gameObject.SetActive(false);
    }
 
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name.Contains("wing"))
        {
            gameObject.SetActive(false);
            //collision.gameObject.SetActive(false);
            var col = collision.GetComponent<BossParts>();
            col.PlayerHit(laserDam);
        }
        else if (collision.name.Contains("Boss"))
        {
            gameObject.SetActive(false);
            var col = collision.GetComponent<UFO>();
            col.PlayerHit(laserDam);
        }
        else if (collision.name.Contains("enemy"))
        {
            gameObject.SetActive(false);
            //collision.gameObject.SetActive(false);
            var col = collision.GetComponent<UFO>();
            col.PlayerHit(laserDam);
        }
    }
 
}
 
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
//ItemManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ItemManager : Singleton<ItemManager>
{
    private Dictionary<int, Queue<GameObject>> itemPool = new Dictionary<int, Queue<GameObject>>();
    public GameObject[] items = null;//0 = powerUp, 1 = shield
    public int[] itemKeyValue = null;
 
    // Use this for initialization
    void Start ()
    {
        CreateItemPool();
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
    
    public void CreateItemPool()
    {
        int tags = 0;
        for(int i = 0; i < 2++i)
        {
            if (items[i].tag.Contains("0"))
                tags = 0;
            if (items[i].tag.Contains("1"))
                tags = 1;
            itemKeyValue[i] = tags;
            if(!itemPool.ContainsKey(itemKeyValue[i]))
            {
                itemPool.Add(itemKeyValue[i], new Queue<GameObject>());
            }
            for(int j = 0; j < 20++j)
            {
                GameObject thisObj = Instantiate(items[i], new Vector3(1001000), Quaternion.identity);
                thisObj.SetActive(false);
                thisObj.transform.parent = this.transform;
                itemPool[itemKeyValue[i]].Enqueue(thisObj);
            }
        }
    }
 
    public GameObject PopItemByPool(int itemType, Vector3 position)
    {
        GameObject thisItem = itemPool[itemType].Dequeue();
        thisItem.transform.position = position;
        thisItem.SetActive(true);
        itemPool[itemType].Enqueue(thisItem);
        return thisItem;
    }
 
    public void AllKillItem()
    {
        foreach(Transform now in this.transform)
        {
            now.gameObject.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
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
//HPBar.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
 
public class HPBar : MonoBehaviour
{
    public GameObject[] hpBar = null;
    public GameObject[] hp = null;
 
    public float HP = 0;
    public float MaxHP = 0;
 
    // Use this for initialization
    void Start()
    {
 
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    public void MakeHPBar()
    {// 체력바부분
        hp = new GameObject[3];
        for (int i = 0; i < 3++i)
            hp[i] = Instantiate(hpBar[i], transform);
        InitHPBarSize();
 
    }
 
    public void InitHPBarSize()
    {
        hp[1].transform.DOScaleX(5.0f, 0);
        hp[1].transform.position = new Vector3(transform.position.x, transform.position.y + 0.5f);
        hp[0].transform.position = new Vector3(transform.position.x - 0.099f * 5, transform.position.y + 0.5f);
        hp[2].transform.position = new Vector3(transform.position.x + 0.099f * 5, transform.position.y + 0.5f);
    }
 
    public void InitHPBarSize(float scale, float size)
    {//나중에 오버로드해서 만들자
        hp[1].transform.DOScaleX(scale, 0);
        hp[1].transform.position = new Vector3(transform.position.x, transform.position.y + 0.5f);
        hp[0].transform.position = new Vector3(transform.position.x - 0.099f * 5, transform.position.y + 0.5f);
        hp[2].transform.position = new Vector3(transform.position.x + 0.099f * 5, transform.position.y + 0.5f);
    }
 
    public void setHpBarSize(float _hp, float _maxHp)
    {
        //원래 짰던 코드
        //HP = _hp;
        //MaxHP = _maxHp;
        //float hpPercent = HP / MaxHP;
        //if (hpPercent < 0)
        //    hpPercent = 0;
        //hp[1].transform.DOScaleX(hpPercent * 5.0f, 0);
        //Vector2 middleBarPos = transform.position;
        //middleBarPos.x -= (1.0f - hpPercent) * 5.0f * 0.099f;
        //middleBarPos.y = hp[1].transform.position.y;
        ////hp[1].transform.position = middleBarPos;
 
 
        //Vector2 RightBarPos = transform.position;
        //RightBarPos.x = transform.position.x + (0.099f * 5.0f);
        //RightBarPos.y = hp[2].transform.position.y;
        //RightBarPos.x -= (1.0f - hpPercent) * 5.0f * 0.198f;
        ////hp[2].transform.position = RightBarPos;
 
        //이건 참조용
        //hp[2].transform.Translate(new Vector3(-0.099f * 5 * hpPercent / 2, 0, 0));
 
 
        HP = _hp;
        MaxHP = _maxHp;
        float hpPercent = HP / MaxHP;
        if (hpPercent < 0)
            hpPercent = 0;
 
        hp[1].transform.DOScaleX(hpPercent * 5.0f, 0);
 
 
 
        hp[2].transform.Translate(new Vector3(-0.099f * 5 * hpPercent / 200));
    }
 
    public void setHpBarSize(float _hp, float _maxHp, int dam)
    {
        HP = _hp;
        MaxHP = _maxHp;
        float hpPercent = HP / MaxHP;
        if (hpPercent < 0)
            hpPercent = 0;
 
        hp[1].transform.DOScaleX(hpPercent * 5.0f, 0);
 
 
        hp[0].transform.Translate(new Vector3((dam / MaxHP) * 0.45f, 00));
        hp[2].transform.Translate(new Vector3(-(dam/MaxHP)*0.45f, 00));
    }
}
 
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
//GaugeManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
 
public class GaugeManager : Singleton<GaugeManager>
{
    private GameManager TheGameManager;
    public GameObject player = null;
    public PlayerLaser pL = null;
    public int maxGauge = 0;
    public int nowGauge = 0;
    public GameObject[] gauge = new GameObject[3];
    public GameObject[] playerGauge = new GameObject[3];
    public bool BoolIsGaugeLive = false;
    public float gaugePlusTime = 0;
    public float gaugeScale = 1.0f;
    public int gaugeScaleLevel = 0;
 
    // Use this for initialization
    void Start()
    {
        TheGameManager = GameManager.Instance;
        pL = player.GetComponent<PlayerLaser>();
        for(int i = 0; i < 3++i)
        {
            playerGauge[i] = Instantiate(gauge[i], transform);
            playerGauge[i].SetActive(false);
            playerGauge[i].transform.position = new Vector2(-4.95f + (0.1575f * i), -4.55f);
        }
    }
 
    // Update is called once per frame
    void Update()
    {
        if (TheGameManager.gameOn)
        {
            if (BoolIsGaugeLive)
            {
                gaugePlusTime += TimeManager.GameTime;
                if (gaugePlusTime > 1.0f)
                {
 
                    if (nowGauge < maxGauge)
                    {
                        gaugePlusTime -= 1.0f;
                        ++nowGauge;
                        SetGaugeBarSize();
                    }
                    else
                        gaugePlusTime = 0;
                }
            }
        }
    }
 
    public int GetNowGauge()
    {
        return nowGauge;
    }
 
    public void GaugeMaxUp()
    {
        if (maxGauge == 0)
            OnGauge();
        if (maxGauge < 50)
        {
            maxGauge += 5;
            ++gaugeScaleLevel;
        }
        if (nowGauge < 46)
            nowGauge += 5;
        else if (nowGauge < 50)
            nowGauge = 50;
        
        SetGaugeBarSize();        
    }
    public void MinusGauge()
    {
        --nowGauge;
        
        gaugePlusTime = 0;
        SetGaugeBarSize();
    }
    public void OnGauge()
    {
        maxGauge = 0;
        nowGauge = 0;
        gaugeScale = 1.0f;
        gaugeScaleLevel = 0;
        gaugePlusTime = 0;
        for (int i = 0; i < 3++i)
            playerGauge[i].SetActive(true);
        BoolIsGaugeLive = true;
    }
 
    public void OffGauge()
    {
        maxGauge = 0;
        nowGauge = 0;
        gaugeScale = 1.0f;
        gaugeScaleLevel = 0;
        gaugePlusTime = 0;
        BoolIsGaugeLive = false;
        for (int i = 0; i < 3++i)
            playerGauge[i].SetActive(false);
    }
 
    public void SetGaugeBarSize()
    {//-4.95f 시작위치, 0.090f 긴 바의 절반, 0.045f 짧은 바의 절반
        gaugeScale = (gaugeScaleLevel + 1* 0.5f * ((float)nowGauge / (float)maxGauge);
        playerGauge[1].transform.DOScaleX(gaugeScale, 0);
        Vector2 middleBarPos = playerGauge[1].transform.position;
        middleBarPos.x = -4.95f + 0.090f * gaugeScale+0.045f;
        playerGauge[1].transform.position = middleBarPos;
 
        Vector2 rightBarPos = playerGauge[2].transform.position;
        rightBarPos.x = -4.95f + 0.090f*2 * gaugeScale+0.045f*2;
        playerGauge[2].transform.position = rightBarPos;
    }
}
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
//GameManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class GameManager : Singleton<GameManager>
{
    private EnemyManager TheEnemyManager;
    private ItemManager TheItemManager;
    private ScoreManager TheScoreManager;
    private EffectManager TheEffectManager;
 
    public GameObject StartButton = null;
    public bool boolInGame = false;
    public GameObject player = null;
    float gameoverDelayTime = 3.0f;
    public float nonDeadTime = 0;
    public GameObject uiPlayerLifeImage = null;
    public GameObject[] uiPlayerLife = null;
    public int nowLife = 0;
    public GameObject uiPlayerBombImage = null;
    public GameObject[] uiPlayerBomb = null;
    public int nowBomb = 3;
    public bool gameOn = false;
    public GameObject PlayerReviveEffect = null;
 
    public bool cheatOn = false;
 
    public AudioClip bgm;
    AudioSource myAudio;
    void Start()
    {
        TheEnemyManager = EnemyManager.Instance;
        TheItemManager = ItemManager.Instance;
        TheScoreManager = ScoreManager.Instance;
        TheEffectManager = EffectManager.Instance;
        for (int i = 0; i < 3++i)
        {
            uiPlayerLife[i] = Instantiate(uiPlayerLifeImage);
            uiPlayerLife[i].transform.position = new Vector2(-4.8f + 0.35f * i, 4.85f);
            uiPlayerLife[i].SetActive(false);
        }
        for (int i = 0; i < 3++i)
        {
            uiPlayerBomb[i] = Instantiate(uiPlayerBombImage);
            uiPlayerBomb[i].transform.position = new Vector2(-4.8f + 0.35f * i, 4.5f);
            uiPlayerBomb[i].SetActive(false);
        }
        myAudio = GetComponent<AudioSource>();
    }
 
    void Update()
    {
        //if (!myAudio.isPlaying)
        //{
        //    PlaySound(bgm);
        //}//bgm 너무 커서 일단 뺌
        if (gameOn)
        {
            if (!boolInGame)
            {
                gameoverDelayTime += TimeManager.GameTime;
                if (gameoverDelayTime >= 3.0f)
                    CheckGameOver();
            }
            else if (nonDeadTime > 0)
            {
                nonDeadTime -= TimeManager.GameTime;
            }
        }
        if (cheatOn)
        {
            if (nowLife < 3)
                nowLife = 3;
            if (nowBomb < 3)
                nowBomb = 3;
            setPlayerBomb();
            setPlayerLife();
        }
    }
 
    public int GetNowBomb()
    {
        setPlayerBomb();
        return nowBomb;
    }
    public void MinusNowBomb()
    {
        --nowBomb;
        setPlayerBomb();
    }
    public void GameOnButtonClick()
    {
        gameOn = true;
        nowLife = 3;
        StartButton.SetActive(false);
        TheScoreManager.ScoreZero();
        CheckGameOver();
    }
    public void CheckGameOver()
    {
        if (nowLife > 0)
        {
            setPlayerLife();
            setPlayerBomb();
            MakePlayer();
            --nowLife;
        }
        else
        {
            GameOver();
        }
    }
 
    public void GameOver()
    {
        TheScoreManager.ScoreOff();
        gameOn = false;
        StartButton.SetActive(true);
        gameoverDelayTime = 3.0f;
        TheEnemyManager.SetWaveZero();
        setPlayerLife();
        setPlayerBomb();
        TheEnemyManager.AllKillGeneralEnemy();
        TheItemManager.AllKillItem();
    }
 
    public void setPlayerLife()
    {
        for (int i = 0; i < 3++i)
        {
            if (i < nowLife)
                uiPlayerLife[i].SetActive(true);
            else
                uiPlayerLife[i].SetActive(false);
        }
    }
 
    public void setPlayerBomb()
    {
        for (int i = 0; i < 3++i)
            if (i < nowBomb)
                uiPlayerBomb[i].SetActive(true);
            else
                uiPlayerBomb[i].SetActive(false);
    }
 
    public void MakePlayer()
    {
        //TheEffectManager.PopEffectByPool(2, transform.position);
        nonDeadTime = 2.0f;
        player.transform.position = new Vector2(0-5.5f);
        player.transform.DOMoveY(-4.5f, 1.0f);
        //깜빡이는거든 뭐든 나중에 여기다 넣으셈
 
        player.SetActive(true);
        boolInGame = true;
        gameoverDelayTime = 0;
    }
 
 
    public void PlaySound(AudioClip a)
    {
        myAudio.PlayOneShot(a);
    }
}
 
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
//EnemyManager.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class EnemyManager : Singleton<EnemyManager>
{
    GameManager TheGameManager;
    Bomb TheBombManager;
    private Dictionary<int, Queue<GameObject>> enemyPool = new Dictionary<int, Queue<GameObject>>();
    public Dictionary<string, Queue<GameObject>> nowEnemyPool = new Dictionary<string, Queue<GameObject>>();
    public GameObject[] enemys = null;
    public GameObject[] enemyFather = null;
    //0번 : 일반 깜장이
    public int[] enemyKeyValue = null;
 
    private int wave = 0//바꿔라
 
    public float respawnTime = 0;
    // Use this for initialization
    void Start()
    {
        TheGameManager = GameManager.Instance;
        TheBombManager = Bomb.Instance;
        CreateEnemyPool();
        nowEnemyPool.Add("Enemy"new Queue<GameObject>());
    }
 
    // Update is called once per frame
    void Update()
    {
        if (TheGameManager.gameOn)
        {
            UFO[] enemys = GetComponentsInChildren<UFO>();
            GameObject closeE = null;
            float fCloseDistance = 1000.0f;
            GameObject playerShip = GameObject.Find("playerShip");
            if (playerShip != null)
            {
                if (!TheBombManager.bombSwitch && !TheBombManager.bombMove)
                {
                    makeEnemy();
                    foreach (UFO e in enemys)
                    {
                        float distance = Vector2.Distance(e.transform.position, playerShip.transform.position);
                        if (distance < fCloseDistance)
                        {
                            closeE = e.gameObject;
                            fCloseDistance = distance;
                        }
                    }
                    playerShip.GetComponent<PlayerLaser>().closeEnemy = closeE;
                }
            }
        }
    }
 
    public void SetWaveZero()
    {
        wave = 0;
    }
 
    void makeEnemy()
    {
        //int r = Random.Range(0, 5);
        //int sideR = Random.Range(-1, 1);
        //if (sideR == 0)
        //    ++sideR; //랜덤으로 나오게 하던 부분
        //int sideR = Random.Range(-1, 2);
        //for (int i = 0; i < 1; ++i)
        //{
        //    //GameObject e = PopEnemyByPool(r, new Vector2(sideR * 5, 4));
        //    EnemyPt1();
        //}
 
 
        respawnTime += TimeManager.GameTime;
        if (wave < 2)
        {
            if (respawnTime >= 3.0f)
            {
                respawnTime -= 3.0f;
                EnemyPt0();
                ++wave;
            }
        }
        else if (wave < 4)
        {
            if (respawnTime >= 6.0f)
            {
                respawnTime -= 6.0f;
                EnemyPt1();
                if (wave.Equals(3))
                    EnemyPt1();
                ++wave;
            }
        }
        else
        {
            switch (wave)
            {
                case 4:
                    if (respawnTime >= 8.0f)
                    {
                        respawnTime -= 8.0f;
                        EnemyPt2();
                        ++wave;
                    }
                    break;
                case 5:
                    if (respawnTime >= 2.0f)
                    {
                        respawnTime -= 2.0f;
                        EnemyPt0();
                        ++wave;
                    }
                    break;
                case 6:
                    if (respawnTime >= 5.0f)
                    {
                        respawnTime -= 5.0f;
                        EnemyPt2();
                        ++wave;
                    }
                    break;
                case 7:
                    if (respawnTime >= 2.0f)
                    {
                        respawnTime -= 2.0f;
                        EnemyPt0();
                        ++wave;
                    }
                    break;
                case 8:
                    if (respawnTime >= 2.0f)
                    {
                        respawnTime -= 2.0f;
                        EnemyPt1();
                        ++wave;
                    }
                    break;
                case 9:
                    if (respawnTime >= 8.0f)
                    {
                        respawnTime -= 8.0f;
                        EnemyPt3();
                        ++wave;
                    }
                    break;
                case 10:
                    if (respawnTime >= 10.0f)
                    {
                        respawnTime -= 10.0f;
                        EnemyPt3();
                        ++wave;
                    }
                    break;
                case 11:
                    if (respawnTime >= 2.0f)
                    {
                        respawnTime -= 2.0f;
                        EnemyPt0();
                        ++wave;
                    }
                    break;
                case 12:
                    if (respawnTime >= 2.0f)
                    {
                        respawnTime -= 2.0f;
                        EnemyPt1();
                        ++wave;
                    }
                    break;
                case 13:
                    if (respawnTime >= 15.0f)
                    {
                        EnemyPt4();
                        ++wave;
 
                    }
                    break;
 
            }
 
 
        }
 
    }
 
 
 
    void EnemyPt0()
    {
        PopEnemyByPool(0new Vector2(-16.5f));
        PopEnemyByPool(0new Vector2(-26));
        PopEnemyByPool(0new Vector2(-37));
        PopEnemyByPool(0new Vector2(16.5f));
        PopEnemyByPool(0new Vector2(26));
        PopEnemyByPool(0new Vector2(37));
    }
 
    void EnemyPt1()
    {
        float r = UnityEngine.Random.Range(-2.0f, 2.0f);
        for (int i = 0; i < 4++i)
        {
            PopEnemyByPool(1new Vector2(r, 5.3f + i * 1.0f));
        }
    }
 
    void EnemyPt2()
    {
        PopEnemyByPool(2new Vector2(06));
    }
 
    void EnemyPt3()
    {
        PopEnemyByPool(3new Vector3(06));
    }
 
    void EnemyPt4()
    {
        PopEnemyByPool(4new Vector3(06));
    }
 
    public void CreateEnemyPool()
    {
        int tags = 0;
        for (int i = 0; i < 5++i)
        {
            if (enemys[i].tag.Contains("0"))
                tags = 0;
            else if (enemys[i].tag.Contains("1"))
                tags = 1;
            else if (enemys[i].tag.Contains("2"))
                tags = 2;
            else if (enemys[i].tag.Contains("3"))
                tags = 3;
            else if (enemys[i].tag.Contains("4"))
                tags = 4// boss
            enemyKeyValue[i] = tags;
            if (!enemyPool.ContainsKey(enemyKeyValue[i]))
            {
                enemyPool.Add(enemyKeyValue[i], new Queue<GameObject>());
            }
            for (int j = 0; j < 50++j)
            {
                GameObject thisFather = Instantiate(enemyFather[i], new Vector3(1001000), Quaternion.identity);
                thisFather.transform.parent = this.transform;
                thisFather.SetActive(false);
                GameObject thisObj = Instantiate(enemys[i], thisFather.transform.position, Quaternion.identity, thisFather.transform);
                enemyPool[enemyKeyValue[i]].Enqueue(thisFather);
                thisFather.GetComponent<HPBar>().MakeHPBar();
                thisFather.GetComponent<HPBar>().HP = thisFather.GetComponent<UFO>().HP;
                thisFather.GetComponent<HPBar>().MaxHP = thisFather.GetComponent<UFO>().MaxHP;
                if (tags.Equals(4))
                    break;//boss는 1마리
                //원래 사용하던 코드
                //GameObject thisObj = Instantiate(enemys[i], new Vector3(100, 100, 0), Quaternion.identity);
                //thisObj.SetActive(false);
                //thisObj.transform.parent = this.transform;
                //enemyPool[enemyKeyValue[i]].Enqueue(thisObj);
                //thisObj.GetComponent<HPBar>().MakeHPBar();
                //thisObj.GetComponent<HPBar>().HP = thisObj.GetComponent<UFO>().HP;
                //thisObj.GetComponent<HPBar>().MaxHP = thisObj.GetComponent<UFO>().MaxHP;
 
            }
        }
    }
 
    public GameObject PopEnemyByPool(int enemyType, Vector3 position)
    {
        GameObject thisEnemy = enemyPool[enemyType].Dequeue();
        thisEnemy.transform.position = position;
        thisEnemy.SetActive(true);
        enemyPool[enemyType].Enqueue(thisEnemy);
        nowEnemyPool["Enemy"].Enqueue(thisEnemy);
        return thisEnemy;
    }
 
    public void AllKillGeneralEnemy()
    {
        foreach (GameObject now in nowEnemyPool["Enemy"])
        {
            now.SetActive(false);
        }
        nowEnemyPool["Enemy"].Clear();
    }
}
 
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
//EnemyCircleBullet.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class EnemyCircleBullet : MonoBehaviour
{
    public Vector2 mDir = new Vector2(0-1.0f);
    public float speed = 0.1f;
    private GameManager TheGameManager;
    private Bomb TheBombManager;
    private ItemManager TheItemManager;
    private EffectManager TheEffectManager;
 
    public AudioClip LaserSound;
    public AudioClip bombSound;
    AudioSource myAudio;
    // Use this for initialization
    void Start ()
    {
        TheItemManager = ItemManager.Instance;
        TheGameManager = GameManager.Instance;
        TheBombManager = Bomb.Instance;
        TheEffectManager = EffectManager.Instance;
        myAudio = GetComponent<AudioSource>();
    }
    
    // Update is called once per frame
    void Update ()
    {
        if (TheGameManager.gameOn)
        {
 
            if (TheGameManager.nonDeadTime <= 0)
            {
                if (TheGameManager.boolInGame)
                {
                    //if (!firstShoot)
                    //{
                    //    mDir = (player.transform.position - transform.position).normalized;
                    //    Quaternion q = new Quaternion();
                    //    float _r = Mathf.Atan2(Vector2.up.x - mDir.x, Vector2.up.y - mDir.y);
                    //    float angle = (_r / Mathf.PI) * 180;
                    //    Debug.Log(angle);
                    //    q.eulerAngles = new Vector3(0, 0, -angle * 2);
                    //    transform.rotation = q;
                    //    firstShoot = true;
                    //}
                }
                if (!TheBombManager.bombSwitch && !TheBombManager.bombMove)
                {
                    Vector2 pos = transform.position;
                    pos += mDir * speed;
                    transform.position = pos;
                }
                Vector2 nowPos = transform.position;
                if (nowPos.x < -5.0f || nowPos.x > 5.0f || nowPos.y < -5.0f || nowPos.y > 5.0f)
                {
                    gameObject.SetActive(false);
                }
 
            }
 
        }
    }
    public void PlaySound(AudioClip a)
    {
        myAudio.PlayOneShot(a);
    }
 
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (TheGameManager.nonDeadTime <= 0)
            if (collision.name.Contains("playerShip"))
            {
                
                if (collision.GetComponent<Shield>().getShield().Equals(-1))
                {
                    PlaySound(bombSound);
                    TheItemManager.PopItemByPool(0this.transform.position);
                    TheItemManager.PopItemByPool(1this.transform.position);
                    collision.gameObject.SetActive(false);
                    TheGameManager.boolInGame = false;
                    collision.GetComponent<PlayerLaser>().InitPower();
                    TheEffectManager.PopEffectByPool(3this.transform.position);
                }
                else
                    collision.GetComponent<Shield>().minusShield();
                gameObject.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
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
//EnemyLazer.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class EnemyLazer : MonoBehaviour
{
    EffectManager TheEffectManager;
    public GameObject player = null;
    private Vector2 mDir = new Vector2(0-1.0f);
    private GameManager TheGameManager;
    private Bomb TheBombManager;
    private ItemManager TheItemManager;
    private bool firstShoot = false;
 
    public AudioClip LaserSound;
    public AudioClip bombSound;
    AudioSource myAudio;
    // Use this for initialization
    void Start()
    {
        TheEffectManager = EffectManager.Instance;
        TheItemManager = ItemManager.Instance;
        player = GameObject.FindGameObjectWithTag("Player");
        TheGameManager = GameManager.Instance;
        TheBombManager = Bomb.Instance;
        myAudio = GetComponent<AudioSource>();
    }
 
    // Update is called once per frame
    void Update()
    {
        if (TheGameManager.gameOn)
        {
 
            if (TheGameManager.nonDeadTime <= 0)
            {
                if (TheGameManager.boolInGame)
                {
                    if (!firstShoot)
                    {
                        mDir = (player.transform.position - transform.position).normalized;
                        Quaternion q = new Quaternion();
                        float _r = Mathf.Atan2(Vector2.up.x - mDir.x, Vector2.up.y - mDir.y);
                        float angle = (_r / Mathf.PI) * 180;
                        Debug.Log(angle);
                        q.eulerAngles = new Vector3(00-angle * 2);
                        transform.rotation = q;
                        firstShoot = true;
                    }
                }
                if (!TheBombManager.bombSwitch && !TheBombManager.bombMove)
                {
                    Vector2 pos = transform.position;
                    pos += mDir * 0.1f;
                    transform.position = pos;
                }
                Vector2 nowPos = transform.position;
                if (nowPos.x < -5.0f || nowPos.x > 5.0f || nowPos.y < -5.0f || nowPos.y > 5.0f)
                {
                    gameObject.SetActive(false);
                    firstShoot = false;
                }
 
            }
 
        }
    }
    public void PlaySound(AudioClip a)
    {
        myAudio.PlayOneShot(a);
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (TheGameManager.nonDeadTime <= 0)
            if (collision.name.Contains("playerShip"))
            {
 
                if (collision.GetComponent<Shield>().getShield().Equals(-1))
                {
                    PlaySound(bombSound);
                    TheItemManager.PopItemByPool(0this.transform.position);
                    TheItemManager.PopItemByPool(1this.transform.position);
                    collision.gameObject.SetActive(false);
                    TheGameManager.boolInGame = false;
                    firstShoot = false;
                    collision.GetComponent<PlayerLaser>().InitPower();
                    TheEffectManager.PopEffectByPool(3this.transform.position);
                }
                else
                    collision.GetComponent<Shield>().minusShield();
                gameObject.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
//EffectObj.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class EffectObj : MonoBehaviour
{
    public bool liveEffect = false;
    public float effectTime = 0;
    public int effectType;
    public float duration;
    // Use this for initialization
    void Start ()
    {
 
    }
    
    // Update is called once per frame
    void Update ()
    {
        if (liveEffect)
        {
            effectTime += TimeManager.GameTime;
            if (effectTime >= duration)
            {
                InitEffect();
            }
        }
    }
    void InitEffect()
    {
        liveEffect = false;
        effectTime = 0;
        gameObject.SetActive(false);
    }
 
    public void EffectOn()
    {
        liveEffect = 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
59
60
61
//EffectManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class EffectManager : Singleton<EffectManager>
{
    public GameObject[] effectsPrefabs = new GameObject[5];
    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 ()
    {
        
    }
 
    void CreateEffectPool()
    {
        int tags = 0;
        for(int i = 0; i < 5++i)
        {
            if (effectsPrefabs[i].tag.Contains("0"))
                tags = 0;
            else if (effectsPrefabs[i].tag.Contains("1"))
                tags = 1;
            else if (effectsPrefabs[i].tag.Contains("2"))
                tags = 2;
            else if (effectsPrefabs[i].tag.Contains("3"))
                tags = 3;
            else if (effectsPrefabs[i].tag.Contains("4"))
                tags = 4;
            if(!effectPool.ContainsKey(tags))
            {
                effectPool.Add(tags, new Queue<GameObject>());
            }
            for(int j = 0; j < 50++j)
            {
                GameObject thisObj = Instantiate(effectsPrefabs[i], new Vector3(1001000), Quaternion.identity);
                thisObj.SetActive(false);
                thisObj.transform.parent = this.transform;
                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
//Button.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Button : MonoBehaviour
{
    GameManager TheGameManager;
    // Use this for initialization
    void Start ()
    {
        TheGameManager = GameManager.Instance;
    }
    
    // Update is called once per frame
    void Update ()
    {
        
    }
    private void OnMouseEnter()
    {
        gameObject.transform.DOScale(3.5f, 0.2f);
    }
    private void OnMouseExit()
    {
        gameObject.transform.DOScale(2.5f, 0.2f);
    }
    private void OnMouseDown()
    {
        gameObject.transform.DOScale(3.0f, 0.2f);
    }
    private void OnMouseUp()
    {
        gameObject.transform.DOScale(2.5f, 0.2f);
        TheGameManager.GameOnButtonClick();
 
    }
 
}
 
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
//BulletManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class BulletManager : Singleton<BulletManager>
{
    private Dictionary<int, Queue<GameObject>> bulletPool = new Dictionary<int, Queue<GameObject>>();
    public GameObject[] bullets = new GameObject[8];
 
    //0번 = 적 레이저, 1번 = 플레이어레이저1, 2번 = 플레이어레이저2, 3번 = 플레이어유도탄
    public int[] bulletKeyValue = new int[8]; // 현재 탄환 4개라 4. 나중에 탄환 추가시 더 넣어라.
 
 
    // Use this for initialization
    void Start()
    {
 
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
 
    public void CreateBulletPool()
    {
        int tags = 0;
        for (int i = 0; i < 8++i)
        {
            if (bullets[i].tag.Contains("0"))
                tags = 0;
            else if (bullets[i].tag.Contains("1"))
                tags = 1;
            else if (bullets[i].tag.Contains("2"))
                tags = 2;
            else if (bullets[i].tag.Contains("3"))
                tags = 3;
            else if (bullets[i].tag.Contains("4"))
                tags = 4;
            else if (bullets[i].tag.Contains("5"))
                tags = 5;
            else if (bullets[i].tag.Contains("6"))
                tags = 6;
            else if (bullets[i].tag.Contains("7"))
                tags = 7;
            bulletKeyValue[i] = tags;
            if (!bulletPool.ContainsKey(bulletKeyValue[i]))
            {
                bulletPool.Add(bulletKeyValue[i], new Queue<GameObject>());
            }
            for (int j = 0; j < 100++j)
            {
                GameObject thisObj = Instantiate(bullets[i], new Vector3(1001000), Quaternion.identity);
                thisObj.SetActive(false);
                thisObj.transform.parent = this.transform;
                bulletPool[bulletKeyValue[i]].Enqueue(thisObj);
            }
        }
    }
 
    public GameObject PopBulletByPool(int bulletType, Vector3 position)
    {
        GameObject thisBullet = bulletPool[bulletType].Dequeue();
        thisBullet.transform.position = position;
        thisBullet.SetActive(true);
        bulletPool[bulletType].Enqueue(thisBullet);
        return thisBullet;
    }
 
    public GameObject PopBulletByPool(int bulletType, Vector3 position, Vector2 dir, float spd = 0.1f)
    {
        GameObject thisBullet = bulletPool[bulletType].Dequeue();
        thisBullet.transform.position = position;
        thisBullet.GetComponent<EnemyCircleBullet>().mDir = dir;
        thisBullet.GetComponent<EnemyCircleBullet>().speed = spd;
        thisBullet.SetActive(true);
        bulletPool[bulletType].Enqueue(thisBullet);
        return thisBullet;
    }
}
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
//BossParts.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class BossParts : MonoBehaviour
{
    EffectManager TheEffectManager;
    GameManager TheGameManager;
    ScoreManager TheScoreManager;
    public float MaxHP = 250.0f;
    public float HP = 250.0f;
    // Use this for initialization
    public AudioClip LaserSound;
    public AudioClip bombSound;
    AudioSource myAudio;
    void Start ()
    {
        TheGameManager = GameManager.Instance;
        TheScoreManager = ScoreManager.Instance;
        TheEffectManager = EffectManager.Instance;
        myAudio = GetComponent<AudioSource>();
    }
    
    // Update is called once per frame
    void Update ()
    {
        
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name.Contains("playerShip"))
        {
            if (TheGameManager.nonDeadTime <= 0)
            {
                if (collision.GetComponent<Shield>().getShield().Equals(-1))
                {
                    collision.gameObject.SetActive(false);
                    TheGameManager.boolInGame = false;
                    collision.GetComponent<PlayerLaser>().InitPower();
                }
                else
                    collision.GetComponent<Shield>().minusShield();
            }
        }
    }
    public void PlaySound(AudioClip a)
    {
        myAudio.PlayOneShot(a);
    }
    public void PlayerHit(int dam)
    {
        HP -= dam;
        if (HP <= 0 && gameObject.transform.position.x != 100)
        {
            PlaySound(bombSound);
            TheEffectManager.PopEffectByPool(4this.transform.position);
            TheScoreManager.ScoreUp(10);
            gameObject.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
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
//Bomb.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Bomb : Singleton<Bomb>
{
    GameManager TheGameManager;
    public GameObject CrossHairManager = null;
    public bool bombSwitch = false;
    public bool bombMove = false;
    public float delayTime = 0;
    public GameObject CrossHairImage = null;
    public Queue<GameObject> CrossHairPool = new Queue<GameObject>();
    private Queue<Collider2D> q = new Queue<Collider2D>();
    private Queue<GameObject> nowCrossHairs = new Queue<GameObject>();
 
    public AudioClip bombSound;
    AudioSource myAudio;
    // Use this for initialization
    void Start ()
    {
        TheGameManager = GameManager.Instance;
        CrossHairManager = GameObject.FindGameObjectWithTag("CrossHairManager");
        CreateCrossHairPool();
        myAudio = GetComponent<AudioSource>();
    }
    
    // Update is called once per frame
    void Update ()
    {
        if(bombMove)
        {
            if(transform.position.x <= 5.1f)
            {
                transform.position = new Vector2(transform.position.x + 20*TimeManager.GameTime, transform.position.y);
            }
            else
            {
                delayTime += TimeManager.GameTime;
                if (delayTime >= 0.5f)
                {
                    bombSwitch = true;
                    bombMove = false;
                    transform.position = new Vector2(-5.1f, 0);
                    BoomTime();
                }
            }
        }
    }
    public void PlaySound(AudioClip a)
    {
        myAudio.PlayOneShot(a);
    }
    public void BombOn()
    {
        if(TheGameManager.GetNowBomb() > 0)
        {
            TheGameManager.MinusNowBomb();
            bombMove = true;
        }
    }
 
    void BoomTime()
    {
        PlaySound(bombSound);
        while (q.Count > 0)
        {
            Collider2D thisCol = q.Dequeue();
            var col = thisCol.GetComponent<UFO>();
            col.PlayerHit(800);
        }
        while(nowCrossHairs.Count>0)
        {
            nowCrossHairs.Dequeue().SetActive(false);
        }
        bombSwitch = false;
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name.Contains("nemy"))
        {
            q.Enqueue(collision);
            GameObject thisCross = PopCrosshairByPool(collision.transform.position);
        }
        //if (collision.name.Contains("nemy"))
        //{
        //    gameObject.SetActive(false);
        //    //collision.gameObject.SetActive(false);
        //    var col = collision.GetComponent<UFO>();
        //    col.PlayerHit(800);
        //}
        else if(collision.tag.Contains("Bullet"))
        {
            collision.gameObject.SetActive(false);
        }
    }
 
    public void CreateCrossHairPool()
    {
        for(int i = 0; i < 50++i)
        {
            GameObject thisObj = Instantiate(CrossHairImage, new Vector3(1001000), Quaternion.identity);
            thisObj.transform.parent = CrossHairManager.transform;
            thisObj.SetActive(false);
            CrossHairPool.Enqueue(thisObj);
        }
    }
 
    public GameObject PopCrosshairByPool(Vector3 pos)
    {
        GameObject thisCross = CrossHairPool.Dequeue();
        thisCross.transform.position = pos;
        thisCross.SetActive(true);
        nowCrossHairs.Enqueue(thisCross);
        CrossHairPool.Enqueue(thisCross);
        return thisCross;
    }
}
 
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
//BackGroundMoveBack.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class BackGroundMoveBack : MonoBehaviour {
    GameManager TheGameManager;
    private const float MOVE_SPEED = 1.0f;
    private const float BG_Y_SIZE = 10.24f;
    // Use this for initialization
    void Start () {
        TheGameManager = GameManager.Instance;
    }
    
    // Update is called once per frame
    void Update () {
        if (TheGameManager.gameOn)
        {
            Transform tr = GetComponent<Transform>();
            tr.Translate(new Vector2(0-MOVE_SPEED * TimeManager.GameTime));
            if (tr.position.y <= -BG_Y_SIZE)
            {
                float fLeftY = tr.position.y + BG_Y_SIZE * 2.0f;
                tr.position = new Vector2(0, fLeftY);
            }
        }
    }
}
 
cs


Comments