}//Selects the enemy to attack public void EnemyTurn() { EnemyHolder.turnCount++; buttons.SetActive(false); enemyTurnAttack = true; #region ResetEnemyAttacks bool enemy0Taken = false; bool enemy1Taken = false; bool enemy2Taken = false; bool enemy3Taken = false; //Clears the lighting effects and enemies so it can reassign them Array.Clear(enemyLightingEffects, 0, enemyLightingEffects.Length); Array.Clear(currentEnemies, 0, currentEnemies.Length); Array.Clear(enemyParticles, 0, enemyParticles.Length); for (int i = 0; i <= EnemyHolder.enemyAmount; i++) { if (GameObject.Find("enemy0") != null && enemy0Taken == false) { enemy0Taken = true; currentEnemies[i] = GameObject.Find("enemy0"); enemyUnit[i] = currentEnemies[i].GetComponent <UnitStats>(); enemyColor[i] = currentEnemies[i].GetComponent <Image>(); enemyParticles[i] = currentEnemies[i].transform.GetChild(3).GetComponent <ParticleSystem>(); enemyHUDs[i].SetHUD(enemyUnit[i]); } else if (GameObject.Find("enemy1") != null && enemy1Taken == false) { enemy1Taken = true; currentEnemies[i] = GameObject.Find("enemy1"); enemyUnit[i] = currentEnemies[i].GetComponent <UnitStats>(); enemyColor[i] = currentEnemies[i].GetComponent <Image>(); enemyParticles[i] = currentEnemies[i].transform.GetChild(3).GetComponent <ParticleSystem>(); enemyHUDs[i].SetHUD(enemyUnit[i]); } else if (GameObject.Find("enemy2") != null && enemy2Taken == false) { enemy2Taken = true; currentEnemies[i] = GameObject.Find("enemy2"); enemyUnit[i] = currentEnemies[i].GetComponent <UnitStats>(); enemyColor[i] = currentEnemies[i].GetComponent <Image>(); enemyParticles[i] = currentEnemies[i].transform.GetChild(3).GetComponent <ParticleSystem>(); enemyHUDs[i].SetHUD(enemyUnit[i]); } else if (GameObject.Find("enemy3") != null && enemy3Taken == false) { enemy3Taken = true; currentEnemies[i] = GameObject.Find("enemy3"); enemyUnit[i] = currentEnemies[i].GetComponent <UnitStats>(); enemyColor[i] = currentEnemies[i].GetComponent <Image>(); enemyParticles[i] = currentEnemies[i].transform.GetChild(3).GetComponent <ParticleSystem>(); enemyHUDs[i].SetHUD(enemyUnit[i]); } }//Reassigns all of the enemies to make sure they are always taking up the first spaces in the array for (int j = 0; j <= EnemyHolder.enemyAmount; j++) { if (currentEnemies[j] != null) { enemyLightingEffects[j] = currentEnemies[j].transform.GetChild(0).gameObject; } }//Assigns the lighting effects for all current enemies if (GameObject.FindGameObjectsWithTag("Enemy0").Length > 0) { enemy0Attack = GameObject.FindGameObjectWithTag("EnemyStuff").GetComponent <Enemy0>(); } if (GameObject.FindGameObjectsWithTag("Enemy1").Length > 0) { enemy1Attack = GameObject.FindGameObjectWithTag("EnemyStuff").GetComponent <Enemy1>(); } if (GameObject.FindGameObjectsWithTag("Enemy2").Length > 0) { enemy2Attack = GameObject.FindGameObjectWithTag("EnemyStuff").GetComponent <Enemy2>(); } //Resets all the enemy attack scripts to make sure there are still scripts to load attacks from #endregion ResetEnemyAttacks for (int i = 0; i <= EnemyHolder.enemyAmount; i++) { if (currentEnemies[i] != null) { if (currentEnemies[i].CompareTag("Enemy0") && currentEnemies[i] != null && enemy0Attack != null) { enemy0Attack.StartCoroutine("EnemyTurn0"); EnemyHolder.coroutinesRunning++; } else if (currentEnemies[i].CompareTag("Enemy1") && currentEnemies[i] != null && enemy1Attack != null) { enemy1Attack.StartCoroutine("EnemyTurn1"); EnemyHolder.coroutinesRunning++; } else if (currentEnemies[i].CompareTag("Enemy2") && currentEnemies[i] != null && enemy2Attack != null) { enemy2Attack.StartCoroutine("EnemyTurn2"); EnemyHolder.coroutinesRunning++; } } }//Runs all enemy coroutines with delays and then sets the coroutines running to 0 if (playerUnit.currentHP <= 0) { state = BattleStateFossil.LOST; StartCoroutine(EndBattle()); } enemyTurnAttack = false; } //Basic enemy turn that will look at which enemy the player is fighting, and start seperate scripts depending on the enemy.