I have drawn a 3D 8x8x8 grid and stored a class containing a cube object and other data into an array. I can select each one independently using mouse, change its colour etc, however I eventually want to load and save a data such as a whether it is selected and the colour of each cube to a file.
This is the first time I have used unity as well as JavaScript, I usually use C++ or Csharp. It seems that I can only have 1 ‘Tag’ for each game object, which is useless for this problem. I have experimented with multidimensional arrays in Javascript etc also, but doesn’t seem suitable.
Is there a good way to attach additional variables to each of the cubes and quickly search for the selected cube in an array? The relationships between game objects and scripts are starting to confuse me.
//Draw cubes and store data
function Awake () {
for(var z=0;z<8;z++)
{
for(var y=0;y<8;y++)
{
for(var x=0;x<8;x++)
{
Instantiate(newCube,position,rotation);
newCube.position = position;
cubeList[cubeCount].Cube = newCube;
cubeCount++;
position.x += 1.1;
}
position.x = 0;
position.y += 1.1;
}
position.y = 0;
position.z += 1.1;
}
}
At the moment to find the cube in the array I am using:
function OnMouseDown()
{
for(i=0;i<511;i++)
{
if(transform.position.x == Main.cubeList*.xpos)*
- {*
_ Main.cubeList*.colour = currentColour;_
_Main.cubeList.selected = isSelected;*_
* }*
}
}