I am stuck on this for 2 days now, can anyone help me please. I am making a grid base dungeon explore game. The issue is when the player go to the next floor ( trigger next scene) and come back, all the enemies and items reappear in the scene. I was able to get my player stats working by using a static class, but I can’t do that for the enemy or pickup because some of them share the same script. What I tried so far is to store each gameobject in the hierarchy into a list to get their name, then assign a bool list to get the current status. So right now I am able to get all the game object that tag with the enemy on the console, and it does output a debug message that tells if the enemy should be destroy on the next load. I tried to set active(false) of the list or destroy the gameobejct in the list, both don’t work. What should I do next?
Below is what my game looks like and script.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class destroyonload : MonoBehaviour
{
// Start is called before the first frame update
public static destroyonload instance;
public static List<GameObject> mylist = new List<GameObject>();
List<GameObject> list1= new List<GameObject>();
public static List<bool> boollist = new List<bool>();
public static List<GameObject> itemlist;
void Awake()
{
DontDestroyOnLoad(this);
if(instance == null)
{
instance = this;
}
else
{
//Duplicate GameManager created every time the scene is loaded
Destroy(gameObject);
}
foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject)))
{
//obj.CompareTag("canbepickup")||
if(obj.CompareTag("enemy")){
Debug.Log(obj.name);
list1.Add(obj);
if(Enemy.shoulddestroy == false){
Debug.Log("First time encounter" + obj);
boollist.Add(false);
}
else{
Debug.Log("the hit object should be destory" + obj);
boollist.Add(true);
}
//array2.AddRange(list1,boollist);
}
}
itemlist.AddRange(list1);
}
void Start()
{
if(itemlist!= null)
{
foreach(GameObject list in mylist){
Debug.Log("attempt to destory list" + list);
if(list.activeInHierarchy){
list.SetActive(false);
Debug.Log("attempt to set active false");
}
Debug.Log("done destory");
}
int i = 0;
while(itemlist*!= null){*
int j =0;
for(j=i;j<itemlist.Count;j++)
{
if(boollist[j] ==true){
Destroy(itemlist*);*
}
}
i=i+1;
}
}
}
}
Enemy Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : Character
{
public static bool shoulddestroy= false;
public int damageStrength;
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag(“Player”)){
shoulddestroy = true;
print(“you should destory on next load”+ other.gameObject);
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.CompareTag(“Player”)){
print(“im out”+ other.gameObject);
}
}