Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Somian · Oct 19, 2013 at 09:52 PM · javascriptarraysfor-loop

going through each item of a multi-dimensional array

Hi,

i have a basic level that consists of a two-dimensional array of GameObjects. How can I delete all of them?

i did

 var board:GameObject[,];
 board = new GameObject[3,3];

and then i want a lil loop that wipes everything out.

 for (var i = 0; i < board.length; i++)
     {
         for (var j = 0; j < board[i].length; j++)
         {
             Destroy(board[i,j]);
         }
     }

doesn't work, though :/ ("'length' is not a member of 'UnityEngine.GameObject'.")

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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Cherno · Oct 19, 2013 at 10:07 PM

You have to use GetLength(dimension) instead of length. the dimension is 0 for first dimemension and 1 for the second (and so on, if you have a 3-dimension array).

 for(var x = 0; x < myArray.GetLength(0); x ++)
     {
         for(var y = 0; y < myArray.GetLength(1); y ++)
             {
                          Destroy(myArray[x,y];
                         }
         }
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 Kiloblargh · Oct 20, 2013 at 01:40 AM 0
Share

And it's Length with a capital L, if it were a single-dimensional array. Also it's usually unnecessary to look up the Length of an array. You should already know how many elements are in an array (just say boardSize : int = 3,) if the number of elements is variable and unknown at runtime, then you should be using a List.

avatar image Eric5h5 · Oct 20, 2013 at 01:53 AM 0
Share

"length" and "Length" both work in Unityscript. It's not that unusual to use Array.Length, since among other reasons you may have it as a public variable in the inspector, in which case you wouldn't just have the length in another variable.

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

17 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

Related Questions

Split() into a fixed length array? 1 Answer

Getting C# to access a javascript global Array and Components 1 Answer

How would I call upon an asset in the projects tab with an array? 1 Answer

Using arrays and for loop with GetComponent error 1 Answer

How to find the index of an Object in an 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