• 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 Kawaburd · Jul 22, 2013 at 11:27 PM · arraylength2d array

Deriving length of a given dimension in a 2D array

'map' in this case is a 2D array of strings, all containing '#' (effectively a blank map to be used in procedural generaion, say, in a roguelike).

 function convertMapToGui (map:String[,]) {
 var mapGuiString: String;
 Debug.Log(map.Length);
 
 for (var x = 0; x < map.Length; x++) {
     for (var y = 0; y < 6; y++) { //Figure out how to get both dims later. '6' ain't gonna cut it. :p
         mapGuiString += (map[x,y].ToString);
         }
     mapGuiString += ('\n');
     }
 return mapGuiString;
 }

What I'm trying for here is a function that will turn that array into a single string I can display by sticking in a GUI box, wich each row being a line of it.

The array is 10x40 and map.Length returns '400', telling me its combining both dimensions and returning that.

Question is, how do I get the length for each dimension on its own?

(Yes, I know there's WAY more wrong here, but I'm posting one question at a time.)

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
0
Best Answer

Answer by Benproductions1 · Jul 22, 2013 at 11:27 PM

http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F

From a single google search :P

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 Kawaburd · Jul 23, 2013 at 12:44 AM 0
Share

As opposed to my 10 or 20. $$anonymous$$ust've been looking up the wrong things or something. Useful info all that, found the answer at the very bottom of the page. Thanks!

avatar image Benproductions1 · Jul 23, 2013 at 01:02 AM 0
Share

I just looked up "Unity Built-in array", trying to find the documentation on how built-in arrays work ;)

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 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

Related Questions

Assets/Gravitation_Simulator.cs(23,47): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `Length' and no extension method `Length' of type `UnityEngine.GameObject' could be found. 2 Answers

2D array generated with custom inspector, null when starting game? 1 Answer

Enemy Wave 1 Answer

variables based on array.length not updating in JS 1 Answer

Mouse Position to 2D array 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