I have two scenes: Menu and Game where the maze is randomly generated every launch.
After the Player dies in the maze I load the scene Menu where the Player can press button Start which should generate a new maze but instead it just loads the old scene with maze where Player died earlier.
I want to generate the new maze every time after pressing Start button.
Also, when I play the scene with maze separately everything works correctly
For scene loading I use:
SceneManager.LoadScene(sceneIndex);
with indexes defined in Build settings.
If any additional code is needed just ask me and I will add it.
UPDATE
I have a class MazeGenerator where I have delegate and event:
public delegate void MazeReadyAction();
public static event MazeReadyAction OnMazeReady;
Event triggers when the maze is generated and is used in MazeDirecives class to set the Enemies and Coins when the maze is ready.
So that I MazeDirectives have lines:
void Awake()
{
MazeGenerator.OnMazeReady += StartDirectives;
}
void StartDirectives()
{
for (int i = 0; i < mazeCoinPositions.Count; i++)
{
MazeCoin mazeCoin = Instantiate(mazeCoinPrefab, mazeCoinPositions[i],
Quaternion.identity) as MazeCoin;
mazeCoin.transform.SetParent(transform);
}
}
Error:MissingReferenceException: The object of type 'MazeDirectives' has been destroyed but you are still trying to access it pups up on:
mazeCoin.transform.SetParent(transform);
Any suggestions?