Thank you for taking time to review this issue.
I have an Empty Game Object with this script attached:
using UnityEngine;
public class FishManager : MonoBehaviour
{
static FishManager instance = null;
void Awake()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
GameObject.DontDestroyOnLoad(gameObject);
}
}
}
Then I have this script attached to the children of that object:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Unlockables : MonoBehaviour
{
public int unlockedAtLevel = 5;
private LevelManager levelManager;
void Start ()
{
levelManager = LevelManager.instance;
}
void Update ()
{
gameObject.SetActive(levelManager.currentLevel >= unlockedAtLevel);
}
}
LevelManager is also another script attached to an empty object, which is named LevelManager, that is DontDestroyOnLoad as well.
When I do this with other objects in the scene that are NOT DontDestroyOnLoad, everything works great!
However, when I have a DontDestroyOnLoad Parent Object with children that I want to activate it does not work.
Let’s say a FishManager Object that has a DontDestroyOnLoad script attached with prefabs of fish as children objects and the Unlockables Script attached to the fish prefabs… the fish prefab does not activate when the currentLevel is achieved.
In the Unity Editor, the script is Active and the child-object is deactivated, as it should be. But the child-object never activates when the bool = true.