Subversion Repository Public Repository

Nextrek

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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class EnemyPool : MonoBehaviour 
{
	public static EnemyPool Instance;
	public Transform[] enemyPrefeb;

	private bool startGame =  false;
	private Transform spaceShip;

	//当前屏幕中活动的敌人
	private int nowEnemy = 0;
	//屏幕中活动的最大数量
	private int maxEnemy = 3;
	//敌人总量
	private int totalEnemy = 0;
	//当前还未死的敌人
	public int aliveEnemy = 100;
	private int[] enemyArray;
	//当前创建的ID
	private int nowID = 0;

	void Awake()
	{
		Instance = this;
		enemyArray = new int[100];
	}

	void Start()
	{
		spaceShip = GameManager.Instance.spaceShip;
	}

	public void InsertEnemy(int type,int cnt)
	{
		for(int i=0;i<cnt;i++)
		{
			enemyArray[totalEnemy++]=type;
			aliveEnemy = totalEnemy;

			Transform tp = Instantiate(enemyPrefeb[type], Vector3.zero, Quaternion.identity) as Transform;
			tp.tag = "Enemy";
			//tp.GetComponentInChildren<EnemyShip>().ID = nowID;

			nowID++;
			nowEnemy++;
			Debug.Log("insert "+type+" "+"tot:"+totalEnemy);
		}
	}
	public void DestroyOneEnemy(int id)
	{
		Debug.Log("Destroy:"+id);
		enemyArray[id]=-1;
		aliveEnemy--;
		nowEnemy--;
	}
	public void StartGame()
	{
		startGame = true;
	}
	void CheckToCreateOneEnemy()
	{
		if(nowEnemy<maxEnemy && nowID<totalEnemy)
		{
		/*	Transform tp = Instantiate(enemyPrefeb[enemyArray[nowID]],Vector3.zero,Quaternion.identity)as Transform;
			if(enemyArray[nowID]<=2)
			{
				tp.name = "EnemyshipRoot";
			}
			tp.GetComponentInChildren<EnemyShip>().ID = nowID;
			nowID++;
			nowEnemy++;
			Radar.Instance.InsertOneShip(tp);*/
		}
	}
	void Update()
	{
		if(startGame)
		{
			CheckToCreateOneEnemy();
		}
	}
	public int hadKilled()
	{
		return totalEnemy - aliveEnemy;
	}
}

Commits for Nextrek/3DSpace/Assets/Custum/Scripts/EnemyPool.cs

Diff revisions: vs.
Revision Author Commited Message
117 Diff Diff DRuega picture DRuega Tue 28 Oct, 2014 13:39:51 +0000
112 Diff Diff FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 14:21:59 +0000
107 FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 11:56:46 +0000