Hello,
i’m attempting to create a top down terrain using 64 x 64 sprites;
i currently have 2 sprites stone and grass.
i have the following script that uses to for loops to copy the sprites using the instantiate function into a 10 x 10 grid (i understand is this a messy and inefficient way of doing this but ill change it out at a later date)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelGen : MonoBehaviour
{
static int mapwidth = 10;
static int maphight = 10;
static int tilesize = 64;
public GameObject Grass;
public GameObject Stone;
static Vector3 mapsize = new Vector3(0,0,0);
static int tileid = 0;
void Start()
{
for (int i = 0; i < mapwidth; i++)
{
for (int a = 0; a < maphight; a++)
{
tileid = Random.Range(1, 10);
if (tileid <= 10)
{
GameObject GrassClone = Instantiate(Grass, mapsize, Quaternion.identity);
mapsize.x = mapsize.x + tilesize;
Debug.Log("Grass Created at" + mapsize);
}
else if (tileid == 1)
{
GameObject StoneClone = Instantiate(Stone, mapsize, Quaternion.identity);
mapsize.x = mapsize + tilesize;
Debug.Log("Stone Created at " + mapsize);
}
mapsize.y = mapsize.y + tilesize;
}
}
}
}
The expected outcome of the script is as stated above a 10 x 10 grid of sprites.
the actual outcome of the script is a infinite number of clones of the sprite non of which are actually viable in the game.
what am i missing and or doing wrong?