Nextrek
Diff Revisions
126
vs
127
for /3DSpace/Assets/Custum/Scripts/EnemyPool.cs
|
@@ -5,21 +5,22 @@ |
5 |
5 |
|
public class EnemyPool : MonoBehaviour |
6 |
6 |
|
{ |
7 |
7 |
|
public static EnemyPool Instance; |
|
8 |
+ |
|
8 |
9 |
|
public Transform[] enemyPrefeb; |
9 |
10 |
|
|
10 |
11 |
|
private bool startGame = false; |
11 |
12 |
|
|
12 |
|
- |
//当前屏幕中活动的敌人 |
13 |
|
- |
private int nowEnemy = 0; |
14 |
|
- |
//屏幕中活动的最大数量 |
15 |
|
- |
private int maxEnemy = 3; |
16 |
|
- |
//敌人总量 |
17 |
|
- |
private int totalEnemy = 0; |
18 |
|
- |
//当前还未死的敌人 |
19 |
|
- |
public int aliveEnemy = 100; |
|
13 |
+ |
private int totalEnemies = 0; |
|
14 |
+ |
private int killedEnemies = 0; |
|
15 |
+ |
|
|
16 |
+ |
private int aliveEnemies = 0; |
|
17 |
+ |
|
|
18 |
+ |
private static int MAX_ENEMY = 100; |
|
19 |
+ |
private static float SPAWING_TIME = 3; // every 3 secs |
20 |
20 |
|
|
21 |
|
- |
//当前创建的ID |
22 |
|
- |
private int nowID = 0; |
|
21 |
+ |
private float _timer = SPAWING_TIME; |
|
22 |
+ |
|
|
23 |
+ |
List<int> toBeCreated = new List<int>(); |
23 |
24 |
|
|
24 |
25 |
|
void Awake() |
25 |
26 |
|
{ |
|
@@ -32,52 +33,57 @@ |
32 |
33 |
|
|
33 |
34 |
|
public void InsertEnemy(int type,int cnt) |
34 |
35 |
|
{ |
|
36 |
+ |
totalEnemies += cnt; |
|
37 |
+ |
|
35 |
38 |
|
for(int i=0;i<cnt;i++) |
36 |
39 |
|
{ |
37 |
|
- |
totalEnemy++; |
38 |
|
- |
aliveEnemy = totalEnemy; |
39 |
|
- |
|
40 |
|
- |
GameManager.CreateEnemy(enemyPrefeb[type]); |
41 |
|
- |
|
42 |
|
- |
nowID++; |
43 |
|
- |
nowEnemy++; |
44 |
|
- |
Debug.Log("enemy "+type+" "+"tot:"+totalEnemy); |
|
40 |
+ |
// push |
|
41 |
+ |
toBeCreated.Add(i); |
45 |
42 |
|
} |
|
43 |
+ |
|
|
44 |
+ |
Debug.Log("adding enemy type:" + type + " " + " count: "+cnt); |
46 |
45 |
|
} |
|
46 |
+ |
|
47 |
47 |
|
public void DestroyOneEnemy(GameObject enemy) |
48 |
48 |
|
{ |
49 |
49 |
|
Debug.Log("Enemy Destroyed"); |
50 |
|
- |
aliveEnemy--; |
51 |
|
- |
nowEnemy--; |
|
50 |
+ |
aliveEnemies--; |
|
51 |
+ |
killedEnemies++; |
52 |
52 |
|
} |
|
53 |
+ |
|
53 |
54 |
|
public void StartGame() |
54 |
55 |
|
{ |
55 |
56 |
|
startGame = true; |
56 |
57 |
|
} |
57 |
|
- |
void CheckToCreateOneEnemy() |
|
58 |
+ |
|
|
59 |
+ |
void Update() |
58 |
60 |
|
{ |
59 |
|
- |
if(nowEnemy<maxEnemy && nowID<totalEnemy) |
|
61 |
+ |
if (startGame) |
60 |
62 |
|
{ |
61 |
|
- |
/* Transform tp = Instantiate(enemyPrefeb[enemyArray[nowID]],Vector3.zero,Quaternion.identity)as Transform; |
62 |
|
- |
if(enemyArray[nowID]<=2) |
|
63 |
+ |
_timer -= Time.deltaTime; |
|
64 |
+ |
if (_timer < 0) |
63 |
65 |
|
{ |
64 |
|
- |
tp.name = "EnemyshipRoot"; |
|
66 |
+ |
_timer += SPAWING_TIME; |
|
67 |
+ |
|
|
68 |
+ |
if (aliveEnemies < MAX_ENEMY) |
|
69 |
+ |
{ |
|
70 |
+ |
if (toBeCreated.Count > 0) |
|
71 |
+ |
{ |
|
72 |
+ |
// pop |
|
73 |
+ |
int type = toBeCreated[0]; |
|
74 |
+ |
toBeCreated.RemoveAt(0); |
|
75 |
+ |
|
|
76 |
+ |
GameManager.CreateEnemy(enemyPrefeb[type]); |
|
77 |
+ |
|
|
78 |
+ |
aliveEnemies++; |
|
79 |
+ |
} |
|
80 |
+ |
} |
65 |
81 |
|
} |
66 |
|
- |
tp.GetComponentInChildren<EnemyShip>().ID = nowID; |
67 |
|
- |
nowID++; |
68 |
|
- |
nowEnemy++; |
69 |
|
- |
Radar.Instance.InsertOneShip(tp);*/ |
70 |
82 |
|
} |
71 |
83 |
|
} |
72 |
|
- |
void Update() |
73 |
|
- |
{ |
74 |
|
- |
if(startGame) |
75 |
|
- |
{ |
76 |
|
- |
CheckToCreateOneEnemy(); |
77 |
|
- |
} |
78 |
|
- |
} |
79 |
|
- |
public int hadKilled() |
|
84 |
+ |
|
|
85 |
+ |
public int getRemainingEnemiesToKill() |
80 |
86 |
|
{ |
81 |
|
- |
return totalEnemy - aliveEnemy; |
|
87 |
+ |
return totalEnemies - killedEnemies; |
82 |
88 |
|
} |
83 |
89 |
|
} |