UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create an enemy spawner"
using UnityEngine; using System.Collections; public class EnemySpawner : MonoBehaviour { public GameObject enemyPrefab; public float spawnInterval = 2f; public int maxEnemies = 10; private int currentEnemies = 0; void Start () { InvokeRepeating ("SpawnEnemy", spawnInterval, spawnInterval); } void SpawnEnemy () { if (currentEnemies < maxEnemies) { Instantiate (enemyPrefab, transform.position, Quaternion.identity); currentEnemies++; } } void OnEnemyDeath () { currentEnemies--; } }