Hi guys, I’m a newbie in Unity as well as game making. I’m trying to create a 2D Xonix-like game that needs to store a lot of grid objects. A grid objects contains of {Transform} and {SpriteRenderer}.
The problem is, when I create a 1515 grid, the player is still fine. But when I put the grid onto 3030, it is very laggy.
Here is the code that I’m using:
-
Generating Grid from a file contains character ‘x’ and ‘o’:
int xx = 0; int yy = gridHeight; foreach (char c in text) { if (c == '\r') continue; if (c == '
') {
xx = 0;
yy–;
}
else {
xx++;
gridScript.grid[xx, yy] =
Instantiate(normalTile, new Vector3((float)xx, (float)yy, 8f), Quaternion.identity) as GameObject;
if (c == ‘x’) {
gridScript.GridDisable(gridScript.grid[xx, yy]);
gridScript.totalGrid–;
}
else
{
gridScript.GridEnable(gridScript.grid[xx, yy]);
}
}
}
gridScript.remainingGrid = gridScript.totalGrid;
}
}
-
The GridEnable and GridDisable Script:
public void GridEnable(GameObject tile)
{
tile.renderer.enabled = true;
int x = Mathf.RoundToInt (tile.transform.localPosition.x);
int y = Mathf.RoundToInt (tile.transform.localPosition.y);
gridStatus [x, y] = 0;
}public void GridDisable(GameObject tile) { tile.renderer.enabled = false; int x = Mathf.RoundToInt (tile.transform.localPosition.x); int y = Mathf.RoundToInt (tile.transform.localPosition.y); gridStatus [x, y] = 1; }
Sorry for my bad English (it’s not my native language).
Can I ask a question, what does your Transform object contains of ?
– AracondaCan you rephrase the question? I don't know what you mean.
– Razputin