61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class EnemySpawner : MonoBehaviour
|
|
{
|
|
#region Statication
|
|
|
|
public static EnemySpawner instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
}
|
|
|
|
#endregion
|
|
|
|
[Header("Enemies")]
|
|
public bool canSpawn = true;
|
|
public Enemy[] enemiesToSpawn;
|
|
public List<Transform> spawnPoints;
|
|
public float spawnRate;
|
|
[SerializeField] private float currentSpawnTime;
|
|
[Header("Boss")]
|
|
public Enemy bossEnemy;
|
|
public Transform bossSpawnPoint;
|
|
[Header("Cache")]
|
|
[SerializeField] private Transform enemyFolder;
|
|
[SerializeField] private Marisa player;
|
|
private void Update()
|
|
{
|
|
if (canSpawn)
|
|
{
|
|
currentSpawnTime -= Time.deltaTime;
|
|
if (currentSpawnTime < 0)
|
|
{
|
|
currentSpawnTime = spawnRate;
|
|
SpawnEnemy(enemiesToSpawn[Random.Range(0, enemiesToSpawn.Length)], spawnPoints[Random.Range(0, spawnPoints.Count)].position);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SpawnEnemy(Enemy enemy, Vector3 location)
|
|
{
|
|
Enemy newEnemy = Instantiate(enemy, location, Quaternion.identity);
|
|
newEnemy.transform.SetParent(enemyFolder);
|
|
newEnemy.closestTarget = player; //idk if there's actually gonna be any other target lol
|
|
}
|
|
|
|
public void StartBoss()
|
|
{
|
|
SpawnEnemy(bossEnemy, bossSpawnPoint.position);
|
|
canSpawn = false;
|
|
}
|
|
}
|