void GenerateNext() { float probability = Random.Range(0.0f, 1.0f); int i = 0; while (i < enemies.Length) { probability -= enemies[i].probability; if (probability <= 0.0f) { break; } i++; } i = i >= enemies.Length? enemies.Length - 1 : i; int spawnerIndex = Random.Range(0, spawners.Length); enemiesSelected = enemies[i]; int gameobjectIndex = enemiesSelected.currentSpawnIndex; gameobjectSelected = enemiesSelected.pool[gameobjectIndex]; enemytSelected = enemiesSelected.poolEnemy[gameobjectIndex]; gameobjectSelected.SetActive(false); gameobjectSelected.transform.position = spawners[spawnerIndex].transform.position; enemytSelected.Start(); gameobjectSelected.SetActive(true); enemies[i].currentSpawnIndex++; enemies[i].currentSpawnIndex %= enemiesSelected.poolSize; }
void Spawn(SpawnableEnemy Enemy) { Vector3 EnemyPos = new Vector3(Random.Range(-SpawnWidth, SpawnWidth), SpawnTransform.position.y, SpawnTransform.position.z); GameObject NewEnemy = Instantiate(Enemy.Object, EnemyPos, SpawnTransform.rotation); var HealthComp = NewEnemy.GetComponent <UnitHealth>(); HealthComp.m_localHealth = HealthComp.m_maxHealth + (int)(PlayerManager.GetMaxPlayers() / 2f); Debug.Log(HealthComp.m_maxHealth.Value + " - " + HealthComp.m_localHealth); LevelPointsAvailable -= Enemy.Points; }