This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpaceship.cs
72 lines (57 loc) · 1.54 KB
/
Spaceship.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpaceShip : MonoBehaviour {
public float speed;
public float shotDelay;
public GameObject BulletPrefab;
public bool canShoot;
Transform[] shotPositions;
public GameObject explosion; //폭발할 스프라이트
protected void Explode()
{
GameObject obj = ObjectPool.current.GetObject(explosion);
obj.transform.position = transform.position;
obj.transform.rotation = transform.rotation;
obj.SetActive(true);
}
void Awake()
{
//내 자식에 있는 오브젝트를 전부 가져와서 shotPositions에 넣는다.
shotPositions = new Transform[transform.childCount];
for (int i = 0; i < transform.childCount; ++i)
{
shotPositions[i] = transform.GetChild(i);
}
}
protected void OnEnable()
{
if (canShoot)
InvokeRepeating("Shoot", shotDelay, shotDelay);
}
void OnDisable() //비활성화 됐을 때 들어오는 함수
{
if (canShoot)
CancelInvoke("Shoot");
}
void Shoot()
{
if (ObjectPool.current == null)
{
Debug.LogError("Err");
return; //비행기보다 먼저 생기면 안됨
}
{
AudioSource Audio = GetComponent<AudioSource>();
if (Audio)
Audio.Play();
}
for (int i = 0; i < transform.childCount; ++i)
{
GameObject Obj = ObjectPool.current.GetObject(BulletPrefab);
Obj.transform.position = shotPositions[i].position;
Obj.transform.rotation = shotPositions[i].rotation;
Obj.SetActive(true);
}
}
}