37 lines
1009 B
C#
37 lines
1009 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class SlimeSpawner : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private List<GameObject> slimeTypes;
|
||
|
[SerializeField]
|
||
|
private List<Transform> spawnLocations;
|
||
|
[SerializeField]
|
||
|
private int maxAmount = 5;
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
|
||
|
InvokeRepeating("SpawnSlime", 5, 5);
|
||
|
}
|
||
|
public void SpawnSlime()
|
||
|
{
|
||
|
int alive = GameObject.FindGameObjectsWithTag("Slime").Length;
|
||
|
|
||
|
if (alive == maxAmount)
|
||
|
{
|
||
|
// Max amount of slimes reached.
|
||
|
Debug.LogWarning("Maximum reached");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
float slimeRandom = Random.Range(0, slimeTypes.Count);
|
||
|
float spawnRandom = Random.Range(0, spawnLocations.Count);
|
||
|
Instantiate(slimeTypes[Mathf.RoundToInt(slimeRandom)], spawnLocations[Mathf.RoundToInt(spawnRandom)].position, Quaternion.identity);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|