UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create an enemy spawner"
using UnityEngine; public class EnemySpawner : MonoBehaviour { public GameObject enemyPrefab; public float spawnRate = 1f; private float spawnTimer; // Start is called before the first frame update void Start() { spawnTimer = spawnRate; } // Update is called once per frame void Update() { spawnTimer -= Time.deltaTime; if (spawnTimer <= 0) { SpawnEnemy(); spawnTimer = spawnRate; } } void SpawnEnemy() { Vector3 spawnPosition = new Vector3(Random.Range(-10f, 10f), 1f, Random.Range(-10f, 10f)); Instantiate(enemyPrefab, spawnPosition, Quaternion.identity); } }