-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEnemyGenerator.cs
More file actions
161 lines (115 loc) · 4.07 KB
/
EnemyGenerator.cs
File metadata and controls
161 lines (115 loc) · 4.07 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
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
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Collections;
public class EnemyGenerator : MonoBehaviour
{
public int numberToGenerate = 0;
public UnityEngine.Object enemyPrefab = null;
//public UnityEngine.Object explosionPrefab = null;
private bool isGenerated = false;
public bool raycastingEnabled = false;
public static float startTime = -1;
//public int timeSpan = 20;
void Start()
{
enemies = new List<GameObject>();
}
public static List<GameObject> enemies;
public void WaypointSystemChangedCallback()
{
if (enemies != null && enemies.Count > 0)
{
foreach (GameObject go in enemies)
{
EnemyController ec = go.GetComponent<EnemyController>();
ec.WaypointSystemChangedCallback();
}
}
}
bool Generate ()
{
//GameObject player = GameObject.FindGameObjectWithTag("Player");
//Debug.Log ("Generating enemies");
GameObject wg = GameObject.Find ("WaypointManager");
if (wg == null)
{
Debug.Log ("WaypointGenerator not found");
}
var sources = wg.GetComponent<WaypointManager>().pathNodes;
if (sources == null || sources.Count == 0)
return false;
int index1 = 0;
int counter = 0;
do {
index1 = UnityEngine.Random.Range(0, sources.Count-1);
} while (sources[index1]/*.GetComponent<PathNode>()*/.connections.Count >= 3 /*&& Vector3.Distance(PathNodeTester.sources[index1].position, player.transform.position) < 8*/);
for (int i = 0; i < numberToGenerate; i++)
{
//GameObject go = new GameObject("enemy"+i); /*GameObject.CreatePrimitive(PrimitiveType.Sphere)*/;
/*GameObject enemyBot = GameObject.FindGameObjectWithTag("EnemyBot");
MeshFilter[] filters = enemyBot.GetComponentsInChildren<MeshFilter>();
int counter = 0;
foreach (var filter in filters)
{
var mesh = filter.mesh;
GameObject child = new GameObject("child" + counter);
child.AddComponent<MeshFilter>();
child.GetComponent<MeshFilter>().mesh = mesh;
child.transform.parent = go.transform;
counter++;
}*/
GameObject go = (GameObject) Instantiate(/*GameObject.FindGameObjectWithTag("EnemyBot")*/enemyPrefab, new Vector3(0.0f, 0.5f, 0.0f), Quaternion.identity);
//go.GetComponent<MeshFilter>().mesh = enemyBot.GetComponent<MeshFilter>().sharedMesh;
go.name = "enemy_" + counter;
go.transform.localScale = new Vector3(2.0f, 2.0f, 2.0f);
//go.transform.position = new Vector3(0.0f, 0.5f, 0.0f);
go.transform.position = sources[index1]./*GetComponent<PathNode>().*/Position + new Vector3(0f, 0.5f, 0f);
go.transform.eulerAngles = new Vector3(270, 0, 0);
go.AddComponent<EnemyController>();
//GameObject explosion = (GameObject) Instantiate(explosionPrefab, new Vector3(0.0f, 0.5f, 0.0f), Quaternion.identity);
//explosion.transform.parent = go.transform;
//go.GetComponent<EnemyController>().explosion = explosion;
go.GetComponent<EnemyController>().parent = go;
go.GetComponent<EnemyController>().id = i;
go.GetComponent<BoxCollider>().enabled = false;
//go.GetComponent<EnemyController>().startIndex = index1;
enemies.Add(go);
counter++;
}
return true;
}
/*void OnGUI()
{
if (startTime != -1)
{
int togo = (int) startTime - (int)Time.timeSinceLevelLoad;
GUI.Label(new Rect(1, 60, 200, 30), "Next wave in: " + togo, "box");
}
}*/
void Update()
{
/*if (Time.timeSinceLevelLoad >= startTime)
{
if (!Generate())
return;
startTime = Time.timeSinceLevelLoad + timeSpan;
}*/
if (raycastingEnabled)
{
if (enemies != null && enemies.Count > 0)
{
foreach (GameObject go in enemies)
go.GetComponent<EnemyController>().DoRayCast();
}
}
if (!isGenerated && Generator.generatorDone == true)
{
if (!Generate())
return;
isGenerated = true;
/*if (startTime == -1)
startTime = Time.timeSinceLevelLoad + timeSpan;*/
}
}
}