• 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 /
avatar image
Question by quadack · Mar 28, 2018 at 04:09 PM · programmingnewbienewnew usercell

How do I check if a spot in a cell is missing?

Hi, I am trying to find out if a wall in a maze is broken ( in generation). the maze is divided into cells. I want to look into a cell, for example, cell 0, and check each wall in the cell to see if it's not there. If there is no game object set, north, for example ( I have, North, East, South, and West) I want to be able to debug.log that there is no north. I have had no luck thus far.

Here is what I have so far.

 {
             Debug.Log("started route");
              if(cells[0].north = null)
                     {
                         Debug.Log("no north");
                     }
              if (cells[0].east = null)
                     {
                         Debug.Log("no east");
                     }
         }

I am using t$$anonymous$$s to try and find a path to the exit with code. NOTES: the maze is randomly generated through the code, so I cant modify the walls beforehand. Currently, if I look into a cell with a wall missing it says, NORTH: Missing

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Papnix · Mar 28, 2018 at 04:14 PM

Hi, very quick answer. You don't test anyt$$anonymous$$ng with cells[0].north = null (one single = is an assignation). You need == to test somet$$anonymous$$ng. if(cells[0].north == null) would be better.

Comment

People who like this

0 Show 3 · 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 quadack · Mar 28, 2018 at 04:22 PM 0
Share

Thanks for the quick reply, I tried the code with == instead of =, and I am not getting any return =/. I am testing for null currently,

if(cells[0].north == null) Do you know if null works for missing game objects too? because I am not getting the debug =/

thanks for the help

avatar image Papnix · Mar 28, 2018 at 04:27 PM 0
Share

How do you initialize your cells ? Can I see your code where you fill it ?

avatar image quadack Papnix · Mar 28, 2018 at 04:32 PM 0
Share

My code is posted as an answer so you can see it better,

avatar image

Answer by quadack · Mar 28, 2018 at 04:33 PM

Here is the part of the code where I make the walls from prefabs and put them into cells based on position and orientation.

    public Walls()
         {
             
             intposition = new Vector3(-data.xsize / 2, 0.0f, (-data.ysize / 2) + (wallLength/2));
             Debug.Log(intposition);
             Vector3 myposition = intposition;
             GameObject tempWall;
             wallfolder = new GameObject();
             wallfolder.name = ("wall folder");
             cells = new cell[data.xsize * data.ysize];
             //for bottom plane
     
     
             //for x axis
             for (int i = 0; i < data.ysize; i++)
             {
                 for (int j = 0; j <= data.xsize; j++)
                 {
                     myposition = new Vector3(intposition.x + (j * wallLength) - wallLength / 2, 0.0f, intposition.z + (i * wallLength) - wallLength / 2);
                     tempWall = Instantiate(wall, myposition, Quaternion.identity) as GameObject;
                     tempWall.transform.parent = wallfolder.transform;
                     totalwallcolor++;
     
                 }
     
                
             }
     
             //for y axis
             for (int i = 0; i <= data.ysize; i++)
             {
                 for (int j = 0; j < data.xsize; j++)
                 {
                     myposition = new Vector3(intposition.x + (j * wallLength)  , 0.0f, intposition.z + (i * wallLength) - wallLength );
                     tempWall = Instantiate(wall, myposition, Quaternion.Euler(0f, 90f, 0f)) as GameObject;
                     tempWall.transform.parent = wallfolder.transform;
                     totalwallcolor++;
                 }
     
             }
             CreateCells();
         }
         public void CreateCells()
         {
             lastCells = new List<int>();
             lastCells.Clear();
             totalcells = data.xsize * data.ysize;
             GameObject[] AllWalls;
             int c$$anonymous$$ldren = wallfolder.transform.c$$anonymous$$ldCount;
             AllWalls = new GameObject[c$$anonymous$$ldren];
             cells = new cell[data.xsize * data.ysize];
             int eastWestProcess = 0;
             int c$$anonymous$$ldProcess = 0;
             int termcount = 0;
             //get the int of c$$anonymous$$ldren
             for (int i = 0; i < c$$anonymous$$ldren; i++ )
             {
                 AllWalls[i] = wallfolder.transform.GetC$$anonymous$$ld(i).gameObject;
             }
     
             //assign walls to the cells
             for (int cellprocess = 0; cellprocess < cells.Length; cellprocess++)
             {
                 if (termcount == data.xsize)
                 {
                     eastWestProcess++;
                     termcount = 0;
                 }
                 cells[cellprocess] = new cell();
                 cells[cellprocess].east = AllWalls[eastWestProcess];
                 cells[cellprocess].south = AllWalls[c$$anonymous$$ldProcess + (data.xsize + 1) * data.ysize];
                
            
                 
                     eastWestProcess++;
                 
               
                 termcount++;
                 c$$anonymous$$ldProcess++;
                 cells[cellprocess].west = AllWalls[eastWestProcess];
                 cells[cellprocess].north = AllWalls[(c$$anonymous$$ldProcess 
                     + (data.xsize + 1) * data.ysize) + data.xsize -1];
             }
     
             CreateMaze();
             //test12
         }


Then I apply a DFS to make the maze.

Comment

People who like this

0 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 Papnix · Mar 28, 2018 at 04:49 PM 0
Share

Sorry mate, I didn't quite understand what you are doing and where it's wrong. I don't know if it helps but your array cells is declared two times (line 10 and line 51). Try to print what's in it to see if it is correctly filled.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

83 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Help with Putting GameObjects into a list. 2 Answers

Issues with Translations and OnTriggerExit 0 Answers

How do i make terrain like in the game called genshin impact?, 0 Answers

I was trying to make it do you could only shoot when touching the left side of the screen. I figure I would just add another if parameter, but I don't really know how to add it. (Mobile game) 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