Hi I just started programming and in this tutorial (Level Generation - Unity Learn) I was following every code but something went wrong, here is the code, can you please tell how to fix it, what I did wrong…
using System.Collections;
using System;
using Random = UnityEngine.Random;
using System.Collections.Generic;
using UnityEngine;
public class BoardManager : MonoBehaviour
{
[Serializable]
public class Count
{
public int minimum;
public int maximum;
public Count(int min, int max)
{
minimum = min;
maximum = max;
}
public int row = 8;
public int columns = 8;
public Count wallCount = new Count(5, 9);
public Count foodCount = new Count(1, 5);
public GameObject exit;
public GameObject[ ] floorTiles;
public GameObject[ ] wallTiles;
public GameObject[ ] enemyTiles;
public GameObject[ ] blockwallTiles;
private Transform boardHolder;
private List gridPositions = new
void InitialiseList()
{
gridPositions(clear);
for (int x = 1, x < columns - 1; x++)
{
for (int y = 1, y < row - 1; y++)
}
}
void BoardSetup();
{
boardHolder = new GameObject (“Board”).transform;
for (int x = -1, x < columns + 1; x++)
{
for (int y = -1 y < row +1; x++)
{
GameObject toInstantiate = floorTiles[Random.Range(0.floorTiles.Length)];
if (x == -1 || x == columns || y == -1 || y == row);
toInstantiate = blockwallTiles[Random.Range (0. blockwallTiles.Length)];
GameObject instance = Instantiate(toInstantiate, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
instance.transform.SetParent(boardHolder);
}
}
}
Vector3 RandomPosition();
{
int randomIndex = Random.Rage(0, gridPositions.Count);
Vector3 randomPosition = gridPositions[randomIndex];
gridPositions.RemoveAt(randomIndex);
return randomPosition;
}
void LayoutObjectAtRandom(GameObject[ ] tileArray, int minimum, int maximum)
{
int objectCount = Random.Range(minimum, maximum + 1);
for (int i = 0; i < objectCount; i++)
{
Vector3 randomPosition = Random.Position();
GameObject tileChoice = tileArray[Random.Rage(0, tileArray.Length)];
Instantiate(tileChoice, randomPosition, Quaternion.identity);
public void SetupScene(int level);
{
BoardSetup();
InitialiseList();
LayoutObjectAtRandom(wallTiles, wallCount.minimum, wallCount.maximum);
LayoutObjectAtRandom(foodTiles, foodCount.minimum, foodCount.maximum);
int enemyCount = (int)Mathf.Log(level, 2f);
LayoutObjectAtRandom(enemyTiles, enemyCount, enemyCount);
Instantiate(exit, new Vector3(columns - 1, row - 1, 0F), Quaternion.identity);
}
}