How do I access an object's array?

I’m going to really quickly describe what I’m trying to accomplish, but keep in mind I’m not looking for alternative ways of accomplishing my task - just proper syntax.

I’m creating a maze. The level manager instantiates 3 separate classes to fabricate the maze:

floor = Instantiate(Floor_Prefab)
walls = Instantiate(Walls_Prefab)
drill = Instantiate(Drill_Prefab)

The purpose of “Walls” is to instantiate a series of cubes back to back, creating a solid square grid of cubes. “Walls” stores each Cube gameobject in a 2 dimensional array called “bricks”. A pointer to the cube at the position (x,y,z) is bricks[x,z].

The purpose of “Drill” is to carve a path through my grid of bricks with “Destroy(Walls.bricks[x,z].gameObject”).

In other words, I’m creating a solid grid of cubes with “Walls”, and removing select cubes with “Drill” to carve a path through the maze.

However, I can’t seem to pass my “bricks[ ]” array from “Walls” to “Drill”. I’ve tried a bunch of different strategies, and I just can’t figure out how to make the array “visible” to “Drill”

You can easily pass array info from classes. All you need to know is the scripts component, and the var must be public.

Yeah it’s public. Still can’t figure out how to call the variable. Here’s the walls part:

class Walls (MonoBehaviour):

    public mazeFloor as Floor
    public floorTile as Tile
    public wallBrick as Brick
    public bricks as (Brick, 2)

In “Drill” I’ve tried creates a public variable that points the the “Walls” prefab, but I don’t know how to access the array. I’ve tried:

Class Drill (Monobehavior):

public walls as Walls

Start():

print ( walls.bricks[0,0] )

No luck. It says “bricks doesn’t exist” or something similar. I’ve also tried variations of “GetComponent”, with similar bad luck. It’s obvious I’m missing something fundamental here

This is how I would do it…

public Brick[] bricks;

:confused:

SomeClass Script

///SomeClass
public SomeOtherClass[] someOtherClass;

SomeOtherClass Script

///SomeOtherClass
public SomeClass[] someClass;

Now each of these scripts hold arrays that reference classes of the other. You can do what you will now.

I GOT IT!

Ok, here was the problem: I was trying to import my class “Walls” as a “GameObject”, and Unity couldn’t find my array in the “GameObject” definition. I solved it by importing the script component of my walls gameobject, and accessing the array through that:

//I created a public array in a custom class "Walls":

Class Walls (Monobehavior):

public BrickArray as (bricks, 2)
//And I tried accessing that array from my other class "Drill", who's transform was a child of "Walls":

Class Drill (Monobehavior):

public myWalls as Walls

def Start():

myWalls = transform.parent.gameObject.GetComponent("Walls")
print(myWalls.BrickArray[0,0])