-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cratespawn.cs
73 lines (60 loc) · 2.09 KB
/
Cratespawn.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//this script checks if a crate spawn position is empty, if it is then it spawns a crate enemy
public class Cratespawn : MonoBehaviour {
[SerializeField] public GameObject loc1;
[SerializeField] private GameObject loc2;
[SerializeField] private GameObject loc3;
[SerializeField] private GameObject loc4;
[SerializeField] private GameObject loc5;
[SerializeField] private GameObject enemy;
private float timer = 0.0f;
public float spawnTimer = 10.0f;
// Use this for initialization
void Start () {
Instantiate (enemy, loc1.transform.position, loc1.transform.rotation);
Instantiate (enemy, loc2.transform.position, loc2.transform.rotation);
Instantiate (enemy, loc3.transform.position, loc3.transform.rotation);
Instantiate (enemy, loc4.transform.position, loc4.transform.rotation);
Instantiate (enemy, loc5.transform.position, loc5.transform.rotation);
}
// Update is called once per frame
void Update () {
if (!Physics.CheckSphere(loc1.transform.position, 0.01f)) {
timer += Time.deltaTime;
if (timer >= spawnTimer) {
Instantiate (enemy, loc1.transform.position, loc1.transform.rotation);
timer = 0;
}
}
else if (!Physics.CheckSphere(loc2.transform.position, 0.01f)) {
timer += Time.deltaTime;
if (timer >= spawnTimer) {
Instantiate (enemy, loc2.transform.position, loc2.transform.rotation);
timer = 0;
}
}
else if (!Physics.CheckSphere(loc3.transform.position, 0.01f)) {
timer += Time.deltaTime;
if (timer >= spawnTimer) {
Instantiate (enemy, loc3.transform.position, loc3.transform.rotation);
timer = 0;
}
}
else if (!Physics.CheckSphere(loc4.transform.position, 0.01f)) {
timer += Time.deltaTime;
if (timer >= spawnTimer) {
Instantiate (enemy, loc4.transform.position, loc4.transform.rotation);
timer = 0;
}
}
else if (!Physics.CheckSphere(loc5.transform.position, 0.01f)) {
timer += Time.deltaTime;
if (timer >= spawnTimer) {
Instantiate (enemy, loc5.transform.position, loc5.transform.rotation);
timer = 0;
}
}
}
}