Generation

generate functionSat, 14 Jan 2023

Unity 2d spawn enemies increase speed with time increases

using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpawnManager : MonoBehaviour { public GameObject enemyPrefab; public float spawnRange = 9.0f; public int enemyCount; public int waveNumber = 1; // Update is called once per frame void Update() { enemyCount = FindObjectsOfType<Enemy>().Length; if (enemyCount == 0) { SpawnEnemyWave(waveNumber); waveNumber++; Debug.Log("Next Wave"); } } void SpawnEnemyWave(int enemiesToSpawn) { for (int i = 0; i < enemiesToSpawn; i++) { Instantiate(enemyPrefab, GenerateSpawnPosition(), enemyPrefab.transform.rotation); } } private Vector3 GenerateSpawnPosition() { float spawnPosX = Random.Range(-spawnRange, spawnRange); float spawnPosZ =

Questions about programming?Chat with your personal AI assistant