Files
CastleDefence/Assets/Scripts/SimpleEnemySpawner.cs

29 lines
829 B
C#
Raw Normal View History

2026-04-01 15:46:15 +01:00
using UnityEngine;
public class SimpleEnemySpawner : MonoBehaviour
{
[SerializeField] private EnemyController enemyToSpawn;
[SerializeField] private Transform spawnPoint;
[SerializeField] private float timeBetweenSpawns;
[SerializeField] private int amountToSpawn;
private float spawnCounter;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
spawnCounter = timeBetweenSpawns;
}
// Update is called once per frame
void Update()
{
spawnCounter -= Time.deltaTime;
2026-04-16 16:43:34 +01:00
if(spawnCounter <= 0f && amountToSpawn > 0)
2026-04-01 15:46:15 +01:00
{
spawnCounter = timeBetweenSpawns;
Instantiate(enemyToSpawn, spawnPoint.position, spawnPoint.rotation);
amountToSpawn--;
}
}
}