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 nyxara143 · Feb 21, 2019 at 12:08 PM · 2d array

how to fill elements of adjacents cells of a 4x4 table?

hi! we are making a 4x4 table and need to insert the data in its adjacent cell. we are able to get the adjacent cells but when we are putting the element on each cell, not all cells have content. there is only 1-3 cells with element. how can we solve this problem? thanks in advance :)

here is our code.

//first random position System.Random rnd = new System.Random(); int initA = rnd.Next(1, 4); int initB = rnd.Next(1, 4); Debug.Log("[" + initA + "," + initB + "]");

     // getting neighbors and adding elements
     int[,] adder =  {{-1,-1},{-1,0},{-1,1},
                      {0,-1},      {0,1},
                      {1,-1},{1,0},{1,1}};

     int neighborRow = initA, neighborCol = initB;
     Debug.Log("adder Length: " + adder.Length + " tilegrid length: "+ tileGrid.Length);
     for (int i = 0; i < binDigits.Length; i++)
     {
         int curRow = neighborRow, curCol = neighborCol;

         neighborRow = neighborRow+ adder[i, 0];
         neighborCol = neighborCol + adder[i, 1];
         Debug.Log(i);

         while (neighborRow < 0 || neighborCol < 0  || neighborRow >= 4 || neighborCol >= 4 || isFilled[neighborRow, neighborCol] != false)
         {
             int curRnd = Random.Range(0, 8);
             neighborRow = curRow + adder[curRnd, 0];
             neighborCol = curCol + adder[curRnd, 1];
         }
         Debug.Log("neighbors: [" + neighborRow + "," + neighborCol + "]");

         isFilled[neighborRow, neighborCol] = true;
         Debug.Log("isFilled? " + isFilled[neighborRow, neighborCol]);

         tileGrid[neighborRow, neighborCol] = binDigits[i].ToString();
             Debug.Log("Content{ " + tileGrid[neighborRow, neighborCol] + " }");
         
     }
Comment
Add comment · Show 2
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 xxmariofer · Feb 21, 2019 at 12:47 PM 0
Share

hard to say, whats binDigits? how many times is logging the i value? the code is hard to understand, whats that while for? can you explain what are you trying to achieve in each part?

avatar image nyxara143 · Feb 28, 2019 at 06:42 AM 0
Share

It is okay now. Thank you!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by nyxara143 · Feb 22, 2019 at 02:30 AM

binDigits is an array containing the elements to be put in the tileGrid. Thanks!

Comment
Add comment · Show 2 · 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 xxmariofer · Feb 22, 2019 at 08:12 AM 0
Share

and your issue is that not all the bindigits are being put in the tileGrid?

avatar image nyxara143 xxmariofer · Feb 22, 2019 at 11:13 AM 0
Share

Yes sir. Only 1-3 are being put

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

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

C# 2D GameObject array, why are these two pieces of code not identical? 1 Answer

Using Vector2 as 2D Array Index 1 Answer

Error while spawning multiple objects 1 Answer

Problem with controlling a 2D array to display strings on GUI. 2 Answers

"Fatal error! CheckDisalowAllowcation" when making a huge 2d array 2 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