In one script at the top:
public bool generationDelay = false;
Then in a method, there was only StartCoroutine i added all the IF statement using the bool variable:
private void BeginGame()
{
mazeInstance = Instantiate(mazePrefab) as Maze;
if (generationDelay == true)
{
StartCoroutine(mazeInstance.Generate(generationDelay));
}
else
{
mazeInstance.Generate(generationDelay);
}
}
Then in another script in the Generate method:
public IEnumerator Generate (bool generationDelay) {
if (generationDelay == true)
WaitForSeconds delay = new WaitForSeconds(generationStepDelay);
cells = new MazeCell[size.x, size.z];
List<MazeCell> activeCells = new List<MazeCell>();
DoFirstGenerationStep(activeCells);
while (activeCells.Count > 0) {
yield return delay;
DoNextGenerationStep(activeCells);
}
}
When i added this line inside Generate:
if (generationDelay == true)
I’m getting error on the line:
WaitForSeconds delay = new WaitForSeconds(generationStepDelay);
The error message:
Embedded statement cannot be a declaration or labeled statement
And also error on the line:
On the delay
yield return delay;
The name ‘delay’ does not exist in the current context
What i want is a public bool variable to decide if to use or not StartCoroutine.