public void Spawn() { //Go back if there's no prefab. if (m_Prefab == null) { return; } //If we don't have a holder, make one. if (m_Holder == null) { MakeHolder(); } //Go trough the rows. for (var y = 0; y < m_Rows; y++) { //Go trough the columns. for (var x = 0; x < m_Columns; x++) { //Get the correct position. var pos = new Vector3(x, 0, y); //Get a random number. var spawnNumber = Random.Range(0f, 1f); //If the number is smaller than the hole possiblity, continue without spawning. if (spawnNumber <= m_HolePossiblity) { continue; } //Spawn the prefab. GameObject nObject = Instantiate(m_Prefab, m_Holder); //Set its position. nObject.transform.position = pos; //Get the block. Block block = nObject.GetComponent <Block>(); block.Place(); } } }