- Home /
Question by
Aceria · Jun 04, 2012 at 07:43 PM ·
gridmultidimensional array
2 dimensional grid of GameObjects, access in different GameObje
I have a grid:
var grid : GameObject[,];
function Start(){
for(var y : int = 0; y < gridSizeY; y++){
for(var x : int = 0; x < gridSizeX; x++){
var s : GameObject = Instantiate(square, Vector3(transform.position), Quaternion.identity);
grid[x, y] = s;
}
}
}
When I hover over the square (the one that I instantiated and is stored in the variable "grid") I want to make the squares next to that one a different colour.
So what I have on the square is:
var gridData;
function Start(){
gridData = gameObject.Find("Grid").GetComponent("DefenseGrid");
}
function OnMouseOver(){
gridData.grid[1,2].renderer.material.color = Color.red; //test this
renderer.material.color = Color.red;
}
However, this gives me an error: "MissingFieldException: Field 'UnityEngine.GameObject[,] not found." While any tests within the first scripts show that the grid is properly initialised and has all the proper data in there.
Can anyone explain me what I'm doing wrong? Thanks in advance!
Comment
Your answer
Follow this Question
Related Questions
How to Place and arrange 3D cards using Grid and Bounds 0 Answers
How to name each grid cell in a grid... 0 Answers
Unity2D Grid disappears when zooming out 0 Answers
problem with gap at specific radius 0 Answers
Allign grid with Splatmap 0 Answers