Call array from another script

I’m just trying to access a 2d array in one script from another script but I can’t figure it out… I’m sure its something simple that I’m not understanding but I’m kinda stuck…

BlockGeneration.cs

public GameObject[,] blocks = new GameObject[maxRow, maxCol];
BlockMovement.cs

            for (int count1 = 0; count1 < BlockGeneration.blocks.GetLength(0); count1++)
            {
                for (int count2 = 0; count2 < BlockGeneration.blocks.GetLength(1); count2++)
                {
                    if (BlockGeneration.blocks[count1, count2].transform.position == myTransform.position)
                    {
                        strPosition = count1.ToString() + "," + count2.ToString();
                        Debug.Log("myTrans position" + strPosition); 
                    }
                }
            }

I get this error Error 1 An object reference is required for the non-static field, method, or property ‘BlockGeneration.blocks’

Also, BlockGeneration.blocks.GetLength(0) might throw some errors because its a game object array and I’m trying to use .getLength… any tips on that would be appreciated. For this I can actually just call maxRow and maxCol from the BlockGeneration script so that’s not all that bad…

You have to use GetComponent() to find the BlockGeneration script before you can access its variables. Basically you need an instance of the class.

Regarding the compilation error you’re getting, ‘blocks’ is a non-static member variable, which means that each BlockGeneration instance has its own copy.

If you only need one copy of this array to be in existence at any one time, you can make it static and access it as you are currently. Otherwise, you’ll need an actual instance of the BlockGeneration class available in order to be able to access the ‘blocks’ field.

Yes, this is exactly what I am looking for but when I change the array to static before I even posted the question on the forum I got these errors…so I thought I was doing something really wrong…

public GameObject[,] blocks = new GameObject[maxRow, maxCol];

to

public static GameObject[,] blocks = new GameObject[maxRow, maxCol];

It totally breaks my BlockGeneration script and throws errors

IndexOutOfRangeException: Array index is out of range.
BlockGeneration.CreateBlocks () (at Assets\Scripts\BlockGeneration.cs:103)

Line 103 is inside a case statement where I randomly create colored blocks and load them into blocks array

blocks[rowIndex, colIndex] = (GameObject)Instantiate(GreenBlockPrefab, prefabPosition, Quaternion.identity);

*** SOLVED ***

Thanks guys for the help both answers helped me a lot… static is what I needed and the problem was once I declared my array static I moved it higher in my code for neatness and declared maxRow and maxCol below it which is what caused the line 103 errors.