Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by phenyx · Feb 16, 2016 at 01:04 PM · c#tutorialmazeoverload

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;
 }

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image phenyx · Feb 15, 2016 at 11:37 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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;
  }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image phenyx · Feb 16, 2016 at 08:27 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Survival Shooter Error CS0120 1 Answer

Enemy Follow Player tutorial? 1 Answer

The bolt doesn't move 0 Answers

Tanks Tutorial - Shells not firing properly 0 Answers

Roll a Ball - Beginner Scripting Question 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges