LunarInfantry/Assets/Scripts/EnemySpawner.cs
2026-01-11 04:22:09 -08:00

42 lines
1.2 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
[SerializeField] private Transform enemyFolder;
[SerializeField] private Enemy[] spawnableEnemies;
public List<Transform> spawnLocationPos;
public List<TileObject> spawnLocations;
public void SpawnEnemy(int amount)//Enemy requestedEnemy)
{
while (amount > 0)
{
Enemy newEnemy = Instantiate(spawnableEnemies[Random.Range(0, spawnableEnemies.Length)], enemyFolder);
TileObject spawnLocation = GridManager.instance.FindClosestEmptyTile(spawnLocations[Random.Range(0, spawnLocations.Count)]);
newEnemy.transform.position = spawnLocation.transform.position;
newEnemy.currentTile = spawnLocation;
newEnemy.currentTile.hasUnit = newEnemy;
TurnHandler.instance.enemyEntities.Add(newEnemy);
amount--;
}
}
}