Hello there,
I’m currently working on a project that has an overworld in which the player spends most of their time, but when they collide with a wandering enemy, they get loaded into a different scene where they resolve the fight using turn-based combat. The problem I’m having is that when the combat finishes, the enemy’s overworld GameObject should be destroyed so that the player cannot collide with it again.
The code I have to load a player into the battle scene is this:
public class EnemyWorldBehavior : MonoBehaviour
{
public string battleScene;
void OnTriggerEnter(Collider collider)
{
if(collider.gameObject.tag == "Player" && battleScene != null)
{
SceneManager.LoadScene(battleScene, LoadSceneMode.Single);
// This is where I'd destroy the Enemy GameObject
}
}
//TODO: Add AI that makes the enemy wander throughout the scene somewhat
}
And the code I have that ends the battle is this:
(Note: I followed Brackey’s Tutorial on turn-based combat, so the rest of the code is almost a carbon copy of that. Some changes were made to better suit my project and fix a glaring issue in his tutorial)
IEnumerator EndBattle()
{
if(state == BattleState.WIN)
{
dialogueText.text = "That's a win for you!";
yield return new WaitForSeconds(2);
SceneManager.LoadScene("SampleScene", LoadSceneMode.Single);
}
else if(state == BattleState.LOSE)
{
dialogueText.text = "You have died...";
}
}
I have it set up so that every enemy prefab can go to their own battle scene (which is my current workaround for making each battle pseudorandom with different numbers of enemies appearing in each battle). How can I set it up so that once the battle is resolved (and the player wins) the enemy GameObject in the overworld either calls a function to drop loot and die or is just simply destroyed?