-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemySpawnPoint.js
43 lines (33 loc) · 1.34 KB
/
EnemySpawnPoint.js
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
#pragma strict
var EnemyObj : GameObject;
var EnemyObj2 : GameObject;
var hasSpawned : boolean = false;
function Start () {
hasSpawned = false;
}
function OnTriggerEnter (other : Collider) {
// Instantiate(nextChunk, Vector3(other.gameObject.transform.position.x, 0, 0), Quaternion.identity);
//Instantiate(nextChunk, Vector3(transform.position.x, 0, 0), Quaternion.identity);
if (other.gameObject.tag == "Player" && hasSpawned == false) {
hasSpawned = true;
#if UNITY_EDITOR
Debug.Log("you hit the Enemy spawn point!");
#endif
var EnemyToSpawn : GameObject = Random.value < .65 ? EnemyObj : EnemyObj2;
var spawnedEnemy : GameObject = PoolManager.Spawn(EnemyToSpawn.name);
//spawnedEnemy.transform.position = Vector3(transform.position.x, 0, 0);
spawnedEnemy.transform.localPosition = transform.position;
//spawnedEnemy.transform.rotation = Quaternion.identity;
//to detach from parent, once positioned
spawnedEnemy.transform.parent = null;
//hasSpawned = true;
}
}
function OnTriggerExit (other : Collider) {
if (other.gameObject.tag == "Player" && hasSpawned == true) {
hasSpawned = false;
#if UNITY_EDITOR
Debug.Log("Spawn point has reset at " + transform.position );
#endif
}
}