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 /
avatar image
0
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 this 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
Add comment
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
0

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

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

Comment
Add comment · 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 == ins$$anonymous$$d 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

$$anonymous$$y code is posted as an answer so you can see it better,

avatar image
0

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 children = wallfolder.transform.childCount;
             AllWalls = new GameObject[children];
             cells = new cell[data.xsize * data.ysize];
             int eastWestProcess = 0;
             int childProcess = 0;
             int termcount = 0;
             //get the int of children
             for (int i = 0; i < children; i++ )
             {
                 AllWalls[i] = wallfolder.transform.GetChild(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[childProcess + (data.xsize + 1) * data.ysize];
                
            
                 
                     eastWestProcess++;
                 
               
                 termcount++;
                 childProcess++;
                 cells[cellprocess].west = AllWalls[eastWestProcess];
                 cells[cellprocess].north = AllWalls[(childProcess 
                     + (data.xsize + 1) * data.ysize) + data.xsize -1];
             }
     
             CreateMaze();
             //test12
         }


Then I apply a DFS to make the maze.

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 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.

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

this works for moving, but after i move either left or right it starts slowly moving me in the opposite direction, why? 0 Answers

Help with Putting GameObjects into a list. 2 Answers

Issues with Translations and OnTriggerExit 0 Answers

No coding experience, tried to mash two codes together, but they aren't playing nicely 1 Answer


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