// add a enemy kill when the player kills and enemy public void killedEnemy(CharacterExperience enemyXp) { killCount++; playerXp.stealExp(enemyXp); xpBar.SetXp(playerXp.xp); if (enemyXp.gameObject == lastEnemy.gameObject) { hasRespawned = false; } }
// There are two cases that can occur when the player dies. They either earn another // chance to restore their lost XP, or they failed and the game restarts. override public void Die() { // If the player has not respawned yet, they have a chance to retrieve their // lost XP from the last enemy that killed them if (hasRespawned == false) { base.Die(); currentHealth = getMaxHealth(); healthBar.SetHealth(currentHealth); // Spawn player at spawn point GetComponent <Transform>().position = respawn.position; // Tag the enemy TagEnemy(lastEnemy); // Enemy steals the player's current XP CharacterExperience enemyXp = lastEnemy.GetComponent <CharacterExperience>(); enemyXp.stealExp(playerXp); // Set the XP and count the respawn xpBar.SetXp(playerXp.xp); hasRespawned = true; } else if (hasRespawned == true) { base.Die(); SceneManager.LoadScene("Main"); } }
// add an enemy kill when the player kills and enemy public void killedEnemy(CharacterExperience enemyXp) { // Steal the enemies XP and set the xp killCount++; playerXp.stealExp(enemyXp); xpBar.SetXp(playerXp.xp); // If the character was able to kill the enemy that stole their XP, reset the respawn if (lastEnemy != null && enemyXp.gameObject == lastEnemy.gameObject) { hasRespawned = false; } // Check if the boss was defeated if (enemyXp.CompareTag("Enemy0")) { mouseActive = true; // Display the win screen winScreen.SetActive(true); Time.timeScale = 0; } }
override public void Die() { if (hasRespawned == false) { base.Die(); currentHealth = getMaxHealth(); healthBar.SetHealth(currentHealth); GetComponent <Transform>().position = respawn.position; CharacterExperience enemyXp = lastEnemy.GetComponent <CharacterExperience>(); enemyXp.stealExp(playerXp); xpBar.SetXp(playerXp.xp); hasRespawned = true; } else if (hasRespawned == true) { base.Die(); SceneManager.LoadScene("Main"); } }