overload method take 0 argument type bool Maze generation script
i took a tutorial and made a few alteration to it with the help of a friend but he is occasionally busy this line of code from my game manager is causing the problem while (!Input.GetKeyDown (KeyCode.Space) && !mazeInstance.IsFinished()) { yield return null; } and here is the full scripts
using UnityEngine; using System.Collections;
public class GameManager : MonoBehaviour {
public Maze mazePrefab;
private Maze mazeInstance;
public IntVector2 sizeGM;
public GameObject mazeGO;
public Maze script;
private float
mazeScale;
public float
scaleUp = 5f;
void Start () {
StartCoroutine(BeginGame ());
}
void OnDestroy(){
StopAllCoroutines ();
}
private IEnumerator BeginGame(){
while(true){
mazeInstance = Instantiate (mazePrefab) as Maze;
Debug.Log ("spawn");
mazeGO = GameObject.FindGameObjectWithTag ("MazeSetup");
Debug.Log ("find");
script = mazeGO.GetComponent ("Maze") as Maze;
script.size = (sizeGM);
StartCoroutine (mazeInstance.Generate ());
while (!Input.GetKeyDown (KeyCode.Space) && !mazeInstance.IsFinished()) {
yield return null;
}
Debug.Log ("startScale");
Vector3 mazeScale = mazeGO.transform.localScale;
mazeScale.x += scaleUp;
mazeScale.y += scaleUp;
mazeScale.z += scaleUp;
mazeGO.transform.localScale = mazeScale;
Debug.Log ("finishScale");
Destroy (mazeInstance.gameObject);
}
}
}
and the script being call using UnityEngine; using System.Collections; using System.Collections.Generic;
public class Maze : MonoBehaviour {
public IntVector2 size;
public MazeCell cellPrefab;
public float generationStepDelay;
public MazePassage passagePrefab;
public MazeWall wallPrefab;
private MazeCell[,] cells;
public bool done;
public MazeCell GetCell(IntVector2 coordinates){
return cells [coordinates.x, coordinates.z];
}
public IEnumerator Generate (){
done = false;
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);
}
Debug.Log ("finish");
IsFinished ();
}
private MazeCell CreateCell(IntVector2 coordinates){
MazeCell newCell = Instantiate (cellPrefab) as MazeCell;
cells [coordinates.x, coordinates.z] = newCell;
newCell.coordinates = coordinates;
newCell.name = "Maze Cell " + coordinates.x + ", " + coordinates.z;
newCell.transform.parent = transform;
newCell.transform.localPosition = new Vector3 (coordinates.x - size.x * 0.5f + 0.5f, 0f, coordinates.z - size.z * 0.5f + 0.5f);
return newCell;
}
private void DoFirstGenerationStep(List<MazeCell> activeCells){
activeCells.Add (CreateCell (RandomCoordinates));
}
private void DoNextGenerationStep(List<MazeCell> activeCells){
int currentIndex = activeCells.Count - 1;
MazeCell currentCell = activeCells [currentIndex];
if (currentCell.IsFullyInitialized) {
activeCells.RemoveAt (currentIndex);
return;
}
MazeDirection direction = currentCell.RandomUninitializedDirection;
IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2 ();
if (ContainCoordinates (coordinates) && GetCell (coordinates) == null) {
MazeCell neighbor = GetCell (coordinates);
if (neighbor == null) {
neighbor = CreateCell (coordinates);
CreatePassage (currentCell, neighbor, direction);
activeCells.Add (neighbor);
}
else {
CreateWall (currentCell, neighbor, direction);
}
}
else {
CreateWall (currentCell, null, direction);
}
}
private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction){
MazePassage passage = Instantiate(passagePrefab) as MazePassage;
passage.Initialize(cell, otherCell, direction);
passage = Instantiate(passagePrefab) as MazePassage;
passage.Initialize(otherCell, cell, direction.GetOpposite());
}
private void CreateWall(MazeCell cell, MazeCell otherCell, MazeDirection direction){
MazeWall wall = Instantiate(wallPrefab) as MazeWall;
wall.Initialize(cell, otherCell, direction);
if (otherCell != null) {
wall = Instantiate (wallPrefab) as MazeWall;
wall.Initialize (otherCell, cell, direction.GetOpposite ());
}
}
public IntVector2 RandomCoordinates{
get{
return new IntVector2 (Random.Range (0, size.x), Random.Range (0, size.z));
}
}
public bool ContainCoordinates (IntVector2 coordinate){
return coordinate.x >= 0 && coordinate.x < size.x && coordinate.z >= 0 && coordinate.z < size.z;
}
public bool IsFinished(bool d){
d = true;
return d;
}
}
also i am not a heavy programmer but a 3d artist who is learning as best as he can. i was unable to find the answer
Answer by hexagonius · Feb 16, 2016 at 04:08 PM
Line 33:
done = true;
instead of:
IsFinished();
From Line 106:
public bool IsFinished(){
return done;
}
instead of:
public bool IsFinished(bool d){
d = true;
return d;
}
thks you that solve that problem now i have a missing reference null exception from when i delete the maze and reinstantiate it back into the scene and the code where it scale up does not run as well as when ever i press space to stop the generation and redo it. it would freeze and become unresponsive
Your answer
Follow this Question
Related Questions
Survival Shooter Error CS0120 1 Answer
Enemy Follow Player tutorial? 1 Answer
The bolt doesn't move 0 Answers