idle-survivors/Assets/Scripts/Wave/SpawnPackSO.cs

32 lines
1016 B
C#
Raw Normal View History

2023-08-02 17:27:45 -04:00
using System.Collections.Generic;
2023-08-02 17:27:45 -04:00
using System.Collections.ObjectModel;
2023-08-02 17:27:45 -04:00
using DefaultNamespace;
using UnityEngine;
using UnityEngine.Assertions;
namespace Wave
{
[CreateAssetMenu(fileName = "SpawnPack", menuName = "Spawn/Pack", order = 0)]
public class SpawnPackSO : ScriptableObject
{
[SerializeField] private List<Enemy> possibleEnemies;
[SerializeField] [Min(0)] private int minCount;
[SerializeField] [Min(0)] private int maxCount;
2023-08-02 17:27:45 -04:00
public ReadOnlyCollection<Enemy> EnemiesToSpawn()
2023-08-02 17:27:45 -04:00
{
Assert.IsTrue(possibleEnemies.Count > 0);
var count = Random.Range(minCount, maxCount);
var enemiesToSpawn = new List<Enemy>();
for (var i = 0; i < count; i++)
{
var enemyIndex = Random.Range(0, possibleEnemies.Count);
enemiesToSpawn.Add(possibleEnemies[enemyIndex]);
}
2023-08-02 17:27:45 -04:00
return enemiesToSpawn.AsReadOnly();
2023-08-02 17:27:45 -04:00
}
}
}