forked from Hummus-1/Prototipo-Interfaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyGeneration.cs
59 lines (55 loc) · 1.67 KB
/
EnemyGeneration.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class EnemyGeneration : MonoBehaviour
{
public readonly float SPAWNTIME = 30f;
public float spawnInterval;
public float timer;
public bool spawnEnabled;
public GameObject[] slimes;
private static readonly System.Random getRandom = new System.Random();
private readonly Vector3[] spawnPoints = {
new Vector3(11f,3.13f,15.2f),
new Vector3(8.7f,2.9f,19.2f),
new Vector3(4.6f,4.9f,21.8f),
new Vector3(18.2f,1.37f,40f)
};
private Player player;
private bool reduceTime;
// Start is called before the first frame update
void Start() {
player = GameObject.FindWithTag("Player").GetComponent<Player>();
Reset();
}
void Update () {
timer += Time.deltaTime;
if (timer >= spawnInterval) {
GenerateEnemy();
}
if ((player.score % 5 == 0) && reduceTime && (player.score != 0)) {
if (spawnInterval > 10f) {spawnInterval -= 1f;}
reduceTime = false;
} else if (player.score % 5 != 0) {
reduceTime = true;
}
}
// Update is called once per frame
void GenerateEnemy()
{
if (spawnEnabled)
{
int direction = getRandom.Next(0,spawnPoints.Length);
int slime = getRandom.Next(0,slimes.Length);
Instantiate(slimes[slime], spawnPoints[direction], Quaternion.identity);
timer = 0f;
}
}
public void Reset() {
timer = SPAWNTIME;
spawnInterval = SPAWNTIME;
spawnEnabled = false;
reduceTime = true;
}
}