Untitled

 avatar
unknown
csharp
5 months ago
688 B
30
Indexable
using UnityEngine;

// This is an example of how you can spawn a wave of enemies in Unity - Gatsby

public class WaveSpawner : MonoBehaviour
{

    public GameObject enemyPrefab;

    public int enemiesPerWave = 10;
    public float spawnSpacing = 1.5f;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            SpawnWave();
        }
    }

    void SpawnWave()
    {
        for (int i = 0; i < enemiesPerWave; i++)
        {
            Vector3 spawnPosition = gameObject.transform.position + new Vector3(i * spawnSpacing, 0, 0);
            Instantiate(enemyPrefab, spawnPosition, Quaternion.identity);
        }
    }
}
Editor is loading...
Leave a Comment