// Test SpawnWave Coroutine. void SpawnWave() { enemiesSpawned++; Debug.Log(name + ": Testing. Enemies Spawned = " + enemiesSpawned, this); Enemy enemy = Instantiate(enemyPrefab, transform); EnemySpawned?.Invoke(endPath); }
public int spawnRandomEnemy(Action <GameObject> actionToCallOnEnemyDead, Action <GameObject> actionToCallOnEnemyDespawned, out EnemyType enemyTypeSpawned, List <EnemyTypeAmmount> ammounts, int ammountLeft) { //Spawns a random enemy and returns the weight it has List <GameObject> enemiesCanBeSpawned = new List <GameObject> (0); foreach (GameObject enemyPrefab in enemyPrefabsCanSpawn) { EnemyType type = enemyPrefab.GetComponent <EnemySpawned>().enemyType; bool found = false; if (enemyPrefab.GetComponent <EnemySpawned>().pointsCost <= (ammountLeft)) { if (enemyPrefab.GetComponent <EnemySpawned>().maximumEnemiesInPlanet == 0) { enemiesCanBeSpawned.Add(enemyPrefab); } else { foreach (EnemyTypeAmmount eta in ammounts) { if (eta.type.Equals(type)) { if (eta.ammount < enemyPrefab.GetComponent <EnemySpawned>().maximumEnemiesInPlanet) { enemiesCanBeSpawned.Add(enemyPrefab); } found = true; break; } } if (!found) { enemiesCanBeSpawned.Add(enemyPrefab); } } } } if (enemiesCanBeSpawned.Count > 0) { GameObject randomEnemyToSpawn = enemiesCanBeSpawned [UnityEngine.Random.Range(0, enemiesCanBeSpawned.Count)]; GameObject newEnemySpawned = GameObject.Instantiate(randomEnemyToSpawn) as GameObject; newEnemySpawned.transform.position = transform.position; EnemySpawned enemySpawnedC = newEnemySpawned.GetComponent <EnemySpawned> (); enemyTypeSpawned = enemySpawnedC.enemyType; enemySpawnedC.actionToCallOnDie = actionToCallOnEnemyDead; enemySpawnedC.actionToCallOnDespawn = actionToCallOnEnemyDespawned; StartCoroutine(spawnOverTime(newEnemySpawned)); return(enemySpawnedC.pointsCost); } else { enemyTypeSpawned = EnemyType.None; return(0); } }
private static Enemy SpawnEnemy() { var enemy = PoolObjects.Get <Enemy>(); enemy.Transform.SetParent(_enemyContainer); enemy.Speed = _currentEnemySpeed; enemy.Transform.position = GetRandomPosition; EnemyInGame.Add(enemy); EnemySpawned?.Invoke(enemy); return(enemy); }
public GameObject getPrefab(EnemyType type) { foreach (GameObject enemy in enemyPrefabs) { EnemySpawned enemySpawned = enemy.GetComponent <EnemySpawned>(); if (enemySpawned.enemyType.Equals(type)) { return(enemy); } } return(null); }
/// <summary> /// <para>Spawns a random enemy in a random position and saves it to the spawn array</para> /// </summary> private void SpawnNewEnemy() { var randomNumber = Random.Range(0f, 1f); var randomHeight = Random.Range(minY, maxY); var enemy = GetRandomEnemy(randomNumber); var pooleable = enemy.GetNextEnemy(); var position = new Vector2(limitX, randomHeight); pooleable.transform.position = position; var enemySpawned = new EnemySpawned(enemy, position, Time.time - startingTime); spawns[currentSpawnIndex] = enemySpawned; currentSpawnIndex++; totalSpawns++; }
private void Spawn() { if (_enemyCount >= MaxCount) { return; } var enemy = Instantiate(_enemyPrefab, PositionGenerator.GetRandomPosition(PositionSettings), GetRandomRotation()); _enemyCount++; EnemySpawned?.Invoke(enemy); enemy.GetComponent <AircraftController>().Died += () => _enemyCount--; }
void Start() { GameManager.registerPlanetSpawner(gameObject); totalPoints = 0; foreach (Wave wave in waves) { foreach (EnemyTypeAmmount enemyAmmount in wave.enemies) { GameObject enemyPrefab = GameManager.enemyPrefabManager.getPrefab(enemyAmmount.type); EnemySpawned enemySpawned = enemyPrefab.GetComponent <EnemySpawned>(); int costPerUnit = enemySpawned.pointsCost; totalPoints += (costPerUnit * enemyAmmount.ammount); } } planetCorruption = GetComponent <PlanetCorruption> (); }
private void SpawnEnemy() { var spawnPlace = GetSpawnCoords(); var enemySpawned = Instantiate(_enemyPrefabs[Random.Range(0, _enemyPrefabs.Count)], spawnPlace, Quaternion.identity); enemySpawned.transform.parent = _spawnParent; _enemiesSpawned.Add(enemySpawned); EnemySpawned?.Invoke(enemySpawned); var killableEvent = enemySpawned.GetComponent <KillableEvent>(); if (killableEvent != null) { killableEvent.KillableDead += OnKillableDead; } }
private void SpawnEnemy(GameObject toSpawn, Vector3 position) { EnemySpawned spawned = toSpawn.GetComponent <EnemySpawned>(); spawned.actionToCallOnDie = onEnemyDead; spawned.actionToCallOnDespawn = onEnemyDespawned; toSpawn.SetActive(false); GameObject spawnBall = GameObject.Instantiate(GameManager.enemyPrefabManager.getSpawnBall()) as GameObject; spawnBall.GetComponent <SpawnBall>().spawned = toSpawn; float forceX = Random.value - 0.5f; float forceY = Random.value - 0.5f; Vector3 force = new Vector3(forceX, forceY, 0f) * 4f; spawnBall.transform.position = position + force; spawnBall.GetComponent <Rigidbody>().AddForce(force, ForceMode.Impulse); }
/*private void addEnemyType(EnemyType type){ * bool found = false; * foreach(EnemyTypeAmmount ea in enemiesAmmount){ * if(ea.type.Equals(type)){ * ea.ammount++; * found = true; * break; * } * } * if(!found){ * EnemyTypeAmmount ea = new EnemyTypeAmmount(); * ea.type = type; * ea.ammount = 1; * enemiesAmmount.Add(ea); * } * }*/ /*private void substractEnemyType(EnemyType type){ * * bool found = false; * foreach(EnemyTypeAmmount ea in enemiesAmmount){ * if(ea.type.Equals(type)){ * ea.ammount--; * found = true; * break; * } * } * }*/ public void onEnemyDead(GameObject enemy) { if (isActive) { EnemySpawned enemySpawned = enemy.GetComponent <EnemySpawned> (); accumulatedPoints += enemySpawned.pointsCost; currentEnemies.Remove(enemy); if (currentEnemies.Count == 0) { ongoingCurrentWave = false; } GUIManager.setPercentageCorruption((float)accumulatedPoints / (float)totalPoints); /*EnemySpawned enemySpawned = enemy.GetComponent<EnemySpawned> (); * //accumulatedPoints += enemySpawned.pointsCost; * ammountOfActualPointsSpawned -= enemySpawned.pointsCost; * * substractEnemyType (enemySpawned.enemyType);*/ } }
void GenerateEnemy(int health = 100) { int i = Random.Range(0, enemies.Length); var newEnemy = Instantiate(enemies[i], gameObject.transform); var enemyScript = newEnemy.GetComponent <EnemyScript>(); enemyScript.TargetPosition = spawnPosition; enemyScript.MoveTime = TimeToEnter; enemyScript.RotationSpeed = Random.Range(rotSpeedMin, rotSpeedMax); enemyScript.BobAmplitude = bobAmplitude; enemyScript.BobSpeed = bobSpeed; var material = newEnemy.GetComponentInChildren <MeshRenderer>().material; material.SetFloat("_Resolution", Random.Range(noiseResolutionMin, noiseResolutionMax)); material.SetFloat("_Speed", Random.Range(noiseSpeedMin, noiseSpeedMax)); CurrentEnemy = new Enemy(newEnemy, health); EnemySpawned.Invoke(newEnemy); }