42 lines
1.2 KiB
C#
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--;
|
|
}
|
|
}
|
|
|
|
}
|