public void SpawnEnemies(int quantity) { if (_spawnables.Count > 0) { for (int i = 0; i < quantity; i++) { GameObject e = PickRandomEnemy(); if (e == null) { return; } // Instantiate enemy GameObject enemy = Instantiate(e, _enemyEmptyParent.transform); if (_spawnLocation) { enemy.transform.position = _spawnLocation.position; } else { Debug.LogError("Spawn Node does not have a spawn-location transform set and is unable to spawn enemies. Please ensure the transform is set."); Destroy(enemy); return; } // Set the initial position for the NavMeshAgent component UnityEngine.AI.NavMeshAgent agent = enemy.GetComponent <UnityEngine.AI.NavMeshAgent>(); if (agent) { agent.Warp(agent.transform.position); } // Subscribe spawn-zone as listener for enemy's death event Health h = enemy.GetComponentInChildren <Health>(); if (h) { _zone.RegisterEnemyToZone(h); } else { Debug.LogError("Spawn Node attempted to spawn a specified prefab which does not have an attached Health script. Please ensure all enemies have an attached Health script, as it is required for Spawn Zone tracking."); Destroy(enemy); } } } }