AsteroidGame/Assets/Handlers/EnemyHandler.cs

56 lines
1.5 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;
namespace AsteroidGame.Handlers
{
public class EnemyHandler : MonoBehaviour
{
[Header("Parameters")]
[SerializeField] [Range(0.1f, 60f)] float spawnRate = 60f;
[SerializeField] int objectPoolSize = 15;
[Header("Prefabs")]
[SerializeField] GameObject objectPool;
[SerializeField] List<GameObject> enemyPrefabs = new List<GameObject>();
[Header("Lists")]
[SerializeField] List<GameObject> enemyPools = new List<GameObject>();
[SerializeField] List<GameObject> allEnemies = new List<GameObject>();
private void Start()
{
}
public void AddEnemyToAllEnemies(GameObject _enemy)
{
allEnemies.Add(_enemy);
}
public void RemoveEnemy(GameObject _enemy)
{
allEnemies.Remove(_enemy);
}
public List<GameObject> ReturnAllEnemies()
{
return allEnemies;
}
public Vector2Int GetCoordinatesFromPosition(Vector3 position)
{
Vector2Int coordinates = new Vector2Int();
coordinates.x = Mathf.RoundToInt(position.x / UnityEditor.EditorSnapSettings.move.x);
coordinates.y = Mathf.RoundToInt(position.z / UnityEditor.EditorSnapSettings.move.z);
return coordinates;
}
public void NotifyEnemiesOfNewPath()
{
BroadcastMessage("RecalculatePath", SendMessageOptions.DontRequireReceiver);
}
}
}