void CreateCollision(int y) { YLevels lvl = yLevels[y]; GameObject go = new GameObject(); BoxCollider box = go.AddComponent <BoxCollider>(); box.size = new Vector3(sizeX * sizeY + (scaleXZ * 2), 0.2f, sizeZ + (scaleXZ * 2)); box.transform.position = new Vector3((sizeX * scaleXZ) * .5f - (scaleXZ * .5f), y * scaleY, (sizeZ * scaleXZ) * 0.5f - (scaleXZ * .5f)); lvl.collisionObj = go; lvl.collisionObj.name = "lvl" + y + "collision"; }
void CreateGrid() { grid = new Node[sizeX, sizeY, sizeZ]; for (int y = 0; y < sizeY; y++) { YLevels ylvl = new YLevels(); ylvl.nodeParent = new GameObject(); ylvl.nodeParent.name = "level " + y.ToString(); ylvl.y = y; yLevels.Add(ylvl); CreateCollision(y); for (int x = 0; x < sizeX; x++) { for (int z = 0; z < sizeZ; z++) { Node n = new Node(); n.x = x; n.y = y; n.z = z; n.isWalkable = true; if (debugNode) { Vector3 targetPosition = GetWorldCoordinatesFromNode(x, y, z); GameObject go = Instantiate(debugNodeObj, targetPosition, Quaternion.identity ) as GameObject; go.transform.parent = ylvl.nodeParent.transform; go.SetActive(true); } grid[x, y, z] = n; } } } }