This repository was 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
Expand file tree
/
Copy pathEnemy.cs
More file actions
67 lines (52 loc) · 1.42 KB
/
Enemy.cs
File metadata and controls
67 lines (52 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : SpaceShip
{
//Transform[] shotPositions; //총알을 발사하는 위치
//float speed = 1f;
/*
void Awake()
{
//내 자식에 있는 오브젝트를 전부 가져와서 shotPositions에 넣는다.
shotPositions = new Transform[transform.childCount];
for (int i = 0; i < transform.childCount; ++i)
{
shotPositions[i] = transform.GetChild(i);
}
InvokeRepeating("Shoot", 0.1f, 1);
} 생략 */
Animator anim;
void OnEnable()
{
base.OnEnable(); //부모의 OnEnable을 실행
GetComponent<Rigidbody2D>().velocity = transform.up * -1 * speed;
anim = GetComponent<Animator>();
}
public int currentHP = 2;
//처음 만났을 때 한번
void OnTriggerEnter2D(Collider2D other)
{
anim.SetTrigger("Damage");
ObjectPool.current.PoolObject(other.gameObject);
//Destroy(other.gameObject); //부딪힌 총알 제거
--currentHP;
if (currentHP <= 0)
{
Explode();
Destroy(this.gameObject); //부딪힌 적 제거
}
}
/*
public GameObject BulletPrefab;
void Shoot()
{
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);
}
} 생략 */
}