public bool Repopulate() { bool repop = false; for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { if (tiles[x, y] == null) { repop = true; // if empty space is in top row if (y == 0) { tiles[x, y] = Instantiate(tilePrefab); tilescript tileScript = tiles[x, y].GetComponent <tilescript>(); tileScript.SetSprite(Random.Range(0, tileScript.tileColors.Length)); tiles[x, y].transform.parent = gridHolder.transform; tiles[x, y].transform.localPosition = new Vector2(WIDTH - x - xOffset, HEIGHT - y - yOffset); } else { slideLerp = 0; tiles[x, y] = tiles[x, y - 1]; tilescript tileScript = tiles[x, y].GetComponent <tilescript>(); if (tileScript != null) { tileScript.SetupSlide(new Vector2(WIDTH - x - xOffset, HEIGHT - y - yOffset)); } playerscript playerScript = tiles[x, y].GetComponent <playerscript>(); if (playerScript != null) { playerScript.playerPos.Set(x, y); } tiles[x, y - 1] = null; } } } } repopulate = repop; return(repop); }
public void createGrid() { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { // make the boy GameObject newTile = Instantiate(tilePrefab); // get the spot for the boy newTile.transform.parent = gridHolder.transform; newTile.transform.localPosition = new Vector2(WIDTH - x - xOffset, HEIGHT - y - yOffset); // place the boy in the spot tiles[x, y] = newTile; // sprite stuff tilescript tileScript = newTile.GetComponent <tilescript>(); tileScript.SetSprite(Random.Range(0, tileScript.tileColors.Length)); } } }