How to destroy enemies in scene 1 after I loaded scene then back to scene 1 again ?

I have a problem with changing scene between scene 1 and 2 after I trigger scene 1 by onTriggerEnter then I back to scene 1 again with onTriggerEnter another object in scene 2, my point I need to destroy that enemies in scene 1 when Im back I searching it in Google and I dont quit understand, sorry for my poor English.

Well if you just need to destroy all the enemies, you can just give them all the tag “Enemy” and run something like this.

foreach (GameObject g in GameObject.FindGameObjectsWithTag("Enemy"))
{
    Destroy(g);
}

if I try this code, will enemy destroy after I loaded the first scene ? I mean the first time scene 1 get loaded.

All objects from any scene destroyed automatically when another (or even the same) scene is loaded. If enemies are not destroyed, that means they are root objects and you called DoNotDestroyOnLoad for those objects. Move them back to original scene before loading another scene and they will be destroyed along with other objects.

SceneManager.MoveGameObjectToScene(TargetGo, SceneManager.GetActiveScene());

oh thank, its my fault I use enemies instead of a enemy I mean I need to destroy only enemy that I trigger.

It looks like a major misunderstanding here. No matter one or many, all your enemies and all other scene objects must be destroyed automatically by unity engine when you loading another scene.

1 Like

Ty Man,I need to make JRPG style game to its to sad if it cant do this, I think I will back to use 2 camera for switch world scene and battle scene again.

If you are loading battle scene with enemies using additive scene loading, then a call SceneManager.UnloadScene should destroy enemies.

Ok, ty I will try it.