ok, so I have been trying to figure this out for two days now. The for loop in my StartingFloor() function works fine if I comment out the instantiate like, but otherwise, it crashes.
var Tile : GameObject;
var gameStart = true;
function StartingFloor(FloorTile : GameObject) {
var tilesInRow = 7;
var rowsInColumn = 7;
var HALF_ROW = 3;
var TILE_SIZE = 0.24;
var tileY = 0;
for(var tileX = 0; tileX < tilesInRow; tileX++) {
var tilePosition = Vector3(-1 * (HALF_ROW * TILE_SIZE) + (tileX * TILE_SIZE), tileY, 0);
Instantiate(FloorTile, tilePosition, FloorTile.transform.rotation);
if((tileX - (tilesInRow - 1)) % tilesInRow == 0) {
tileY += 1;
}
yield WaitForSeconds(3);
Debug.Log(tileX);
}
}
function Start () {
StartingFloor(Tile);
}
For a start when posting a question use the 101 button to add code like this:
var Tile : GameObject;
var gameStart = true;
function StartingFloor(FloorTile : GameObject)
{
var tilesInRow = 7;
var rowsInColumn = 7;
var HALF_ROW = 3;
var TILE_SIZE = 0.24;
var tileY = 0;
for(var tileX = 0; tileX < tilesInRow; tileX++)
{
var tilePosition = Vector3(-1 (HALF_ROW TILE_SIZE) + (tileX * TILE_SIZE), tileY, 0);
Instantiate(FloorTile, tilePosition, FloorTile.transform.rotation);
if((tileX - (tilesInRow - 1)) % tilesInRow == 0) {
tileY += 1;
}
yield WaitForSeconds(3);
Debug.Log(tileX);
}
}
function Start ()
{
StartingFloor(Tile);
}
As for what the problem is I’m not too sure, make sure the tile position and rotation you are setting is valid, try testing it with the position and rotation set to 000 or something. So for testing purposes try replacing your instantiate with:
I AM SUCH AN IDIOT!!! I attached the script for instantiating the tiles to the tiles. So every time one spawned, it spawned another just like it, and so on and so forth, causing infinite objects to spawn. I easily fixed the problem by creating an empty object named “TileSpawner” and attached the script to that, getting rid of the infinite instantiating problem. Gosh I can be so dumb sometimes.