using UnityEngine;
public class SpawnManager : MonoBehaviour
{
public GameObject enemyPrefab;
public GameObject ammoPrefab;
private int enemyCount;
private int waveNumber = 1;
private float spawnRange = 9;
void Start()
{
SpawnEnemyWaveAndAmmo(waveNumber);
}
// Update is called once per frame
void Update()
{
enemyCount = FindObjectsOfType<Enemy>().Length;
if (enemyCount == 0)
{
waveNumber++;
SpawnEnemyWaveAndAmmo(waveNumber);
Debug.Log(enemyCount);
}
}
private Vector3 GenerateSpawnPosition()
{
float spawnPosX = Random.Range(-spawnRange, spawnRange);
float spawnPosZ = Random.Range(-spawnRange, spawnRange);
Vector3 randomPos = new Vector3(spawnPosX, 1, spawnPosZ);
return randomPos;
}
private void SpawnEnemyWaveAndAmmo(int enemiesToSpawn)
{
Instantiate(ammoPrefab, GenerateSpawnPosition(), ammoPrefab.transform.rotation);
for (int i = 0; i < enemiesToSpawn; i++)
{
Instantiate(enemyPrefab, GenerateSpawnPosition(), enemyPrefab.transform.rotation);
}
}
}
Почему то Enemy = 0
Если private int enemyCount присвоить значение 1 всё равно не работает