I got some error help please

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… :confused:

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);
}
}

Okay, first you should use the code blocks to make it easier to read.

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<Vector3> 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);
}
}

Now since you didn’t specify what kind of error you’re having, I’m just going to assume this is your issue:

using Random = UnityEngine.Random;

I don’t think you need this. I never seen it before. If anything it would be:

using UnityEngine.Random;

However, to use the Random, I think all you need is:

using UnityEngine;
using UnityEngine.Collections;

Why are you importing the System ??? I’m just guessing that your tutorial must be waaaaayyyy out of date and the code is depreciated. However, if you can provide more information, perhaps I can be of more help to you?

1 Like

If you don’t tell what went wrong, nobody will be able to help you.

Before you created this thread, you did make sure that you didn’t make typos in your script did you?

By the way, this tutorial is old, what version of Unity are you using to do it? You should use Unity 5: https://unity3d.com/get-unity/download/archive; it’s not available in the Hub.

2 Likes

To be honest I dont really know why but the person in tutorial said you should use it to able to use it, I think the tutorial is way to old and I have to find another one but thanks for responding me, very appreciated

What is it that you are trying to do and perhaps I can draw you up some code to get’cha started?