Home Technical Talk

unity -3d arrays

polycounter lvl 17
Offline / Send Message
SHEPEIRO polycounter lvl 17
hey there

I'm looking for some good tutorials on 2d and 3d arrays in unity preferably C#

as I'm trying to construct some simple meshes from 3d arrays (think small voxel objects)

I've found a few videos here and there but they are a bit rambling and I'm not totally convinced on the info given

Replies

  • Farfarer
    Offline / Send Message
    Farfarer polycounter lvl 17
    As it's C#, you can just use any C# tutorials - they're not specific to Unity.

    It's only UnityScript that is specific to Unity and I don't think Native UnityScript has the ability to create multidimensional arrays (although it can use them if they've been created in C# and passed over). At least it didn't the last time I looked. Best to stick with C#...

    What sort of stuff are you after?

    Say you wanted to store an int at each location within a 9 x 9 x 9 voxel cube.
    int[, ,] ninebyninecube = new int[9, 9, 9];
    
    // Assuming z-up, fill the top 4 corners of the array with 2.
    ninebyninecube[0,0,8] = 2;
    ninebyninecube[0,8,8] = 2;
    ninebyninecube[8,0,8] = 2;
    ninebyninecube[8,8,8] = 2;
    
    // Assuming z-up, fill the bottom 4 corners of the array with 1.
    ninebyninecube[0,0,0] = 1;
    ninebyninecube[0,8,0] = 1;
    ninebyninecube[8,0,0] = 1;
    ninebyninecube[8,8,0] = 1;
    

    http://www.dotnetperls.com/multidimensional-array
Sign In or Register to comment.