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 youngapprentice · May 21, 2013 at 01:46 AM · array

List of Arrays?

Hi, all!

I constructed a grid for my enemies to use for positioning a while ago. The grid is a series of Vector3's expressed in [ row, column ] form.

Well, I want to spawn randomly selected sets of enemies at specified places in the grid, so I made an enum called EnemyType which has 4 types: Probe, Tank, Bomb, and Null.

For easy placement on the grid, I made temporary variables in the start function that reference these types ( P, T, B, and o for null ).

I need to make an array of these 2D arrays so I can select individual [row, column] enemy sets to be iterated through and spawned.

However, Unity seems to either disagree with the idea of a [,,], or I just don't know how to write it.

Is this wrong?

 #pragma strict
 
 @HideInInspector
 var easySets : EnemyType[,,];
 
 //Creating contaners for our SetArrays
 
 function Start () {
     
     var P : EnemyType = EnemyType.Probe;
     var B : EnemyType = EnemyType.Bomb;
     var T : EnemyType = EnemyType.Tank;
     var o : EnemyType = EnemyType.Null;
     
     // Setting up quick-access, one-key variables to create sets
     //EasySets = new EnemyType[2,7,7];
     easySets = [//START EASY SETS
     
     [P, o, o, o, o, o, P,
     o, P, o, P, o, P, o,
     o, o, P, o, P, o, o,
     o, o, o, o, o, o, o,
     o, o, P, o, P, o, o,
     o, P, o, P, o, P, o,
     P, o, o, o, o, o, P],
     
     [P, o, o, o, o, o, P,
     o, P, o, P, o, P, o,
     o, o, P, o, P, o, o,
     o, o, o, o, o, o, o,
     o, o, P, o, P, o, o,
     o, P, o, P, o, P, o,
     P, o, o, o, o, o, P]
     ]; //END EASY SETS
 
 }

If so, how should I write it? I just want to be able to extract a single 2D Array, iterate through it, and spawn enemies accordingly. The iteration and spawning part I already know how to do, so really I just need help on expressing it.

Thanks a ton! - YA

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 whydoidoit · May 21, 2013 at 02:42 AM

So your initialization there is creating a jagged array of EnemyType:

     var array : EnemyType[][];

This isn't what you were expecting and I don't think that there is a syntax to initialise a multi-dimensional array in any case.

If you wanted to make an array that was 3d jagged var array: EnemyType[][][] then you would need to initialize it like this:

    easySets = [
         [ 
           [P, o, o, o, o, o, P],
           [o, P, o, P, o, P, p],
           ...
          ],
          ...
         ];

This you could access using easySets[x][y][z] rather than easySets[x,y,z];

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 youngapprentice · May 21, 2013 at 11:02 AM 0
Share

Oh. So you are saying that there isn't a manual way to populate a multidimensional array save through iteration?

Jagged array is fine by me as well. However, whenever I type the statement

 var easySets : EnemyType[][][];

I get an error thrown at me about the semicolon at the end. I don't think the compiler is expecting or reading [][][]...

avatar image youngapprentice · May 22, 2013 at 12:02 AM 0
Share

This: http://answers.unity3d.com/questions/54695/how-to-declare-and-initialize-multidimensional-arr.html

tells me that I can't set the type of a jagged array. Thanks for the help! That was the final piece of the puzzle.

avatar image youngapprentice · May 22, 2013 at 01:34 AM 0
Share

Just in case anyone was interested, I wrote a script that would create a square 2D array from a single array of elements (you have to specify how big the square array is in the i and u for loops but it works).

 function $$anonymous$$akeASet( myArray : EnemyType[] ){
     
     var my$$anonymous$$ultiArray : EnemyType[,] = new EnemyType[7,7];
     var q = 0;
     for( var i = 0; i < 7; i++ ){
         for( var u = 0; u < 7; u++){
             my$$anonymous$$ultiArray[i,u] = myArray[ q ];
             q++;        
         }
         }
 }

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

14 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

Related Questions

Talking Code 2 Answers

Arrays with zero length 1 Answer

help with score display concept 2 Answers

Can't get rid of errors 0 Answers

For Loop Array, skip 1 value 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