void Update() { healthBar.SetCurValue(playerEntity.CurrentHealth); bool allDead = true; foreach (bool var in alive) { if (var) { allDead = false; } } if (playerTurn) { if (playerScript.Turn()) { playerTurn = false; battleUIScript.UpdateUI(); } } else { bool done; if (alive[enemyIndex]) { GameObject enemy = enemiesGameObjects[enemyIndex]; EnemyBattleScript enemyScript = enemy.GetComponent <EnemyBattleScript>(); if (enemyScript.Ready()) { done = enemyScript.Turn(); battleUIScript.EnemiesTurn(); } else { done = false; } } else { done = true; } if (done) { enemyIndex++; if (enemyIndex >= enemiesGameObjects.Count) { battleUIScript.ResetTurn(); playerTurn = true; enemyIndex = 0; } } } if (playerDead) { float animTime = playerScript.Disable(); if (animTime > 0) { battleUIScript.BattleResults(false); playerDead = false; Invoke("MoveToForestScene", animTime); } } if (allDead) { if (xpNotCounted) { int sum = 0; foreach (GameObject enemy in enemiesGameObjects) { EnemyBattleScript enemyScript = enemy.GetComponent <EnemyBattleScript>(); sum += enemyScript.entity.Stats.Experience; } playerEntity.CurrentExperience += sum; while (playerEntity.CurrentExperience >= playerEntity.Stats.Experience) { int remainder = playerEntity.CurrentExperience - playerEntity.Stats.Experience; playerEntity.LevelUp(); playerEntity.CurrentExperience += remainder; } won = true; SaveLoadController.data.CurrHealth = playerEntity.CurrentHealth; SaveLoadController.data.CurrExp = playerEntity.CurrentExperience; SaveLoadController.data.CurrLevel = playerEntity.Stats.Level; battleUIScript.BattleResults(true); Invoke("MoveToForestScene", animTime); xpNotCounted = false; } } }