I was following the fourth tutorial video of roguelike scavengers , and I came across with these errors when finished. In the fifth video it fixes some, but these have continued, I'm using the latest version of unity ( 5.1f1
I do not know what else).
Itsaysthatthe3redvariablesintheimagedonotexistinthatcontext,andtheothererrorpointstoalinethatlooksnormal.
Verygoodvideosthathaveexcitedmeenoughtostartmyproject!
Hereisthewholecode:
using UnityEngine;
using System; //Atributo Serializable - aplica variaveis no inspector e editor
using System.Collections.Generic; //Usar lists
using Random = UnityEngine.Random; //Gerar Numeros Aleatorios
public class BoardManager : MonoBehaviour { //padrao
[Serializable] //tipo de variavel
public class Count
{
public int minimum;
public int maximum;
public Count (int min, int max)
{
minimum = min;
maximum = max;
}
}
public int columns = 8; //Quantidade de colunas do mapa
public int rows = 8; //Quantidade de Linhas do mapa
public Count wallCount = new Count (5,9); //quantidade aleatoria de numeros internos
public Count foodCount = new Count (1,5); //quantidade aleatoria de comida
public GameObject exit; //objetos do jogo, q vao aparecer no mapa ->
public GameObject [] floorTiles;
public GameObject [] wallTiles;
public GameObject [] foodTiles;
public GameObject [] enemyTiles;
public GameObject [] outerWallTiles; // <-
private Transform boardHolder; //segura tds os objetos no mapa
private List <Vector2> gridPosition = new List<Vector2> (); //lista de posiscoes possiveis no mapa
void initialiseList () //limpar a lista do grid e preparar para gerar novo mapa
{
gridPosition.Clear (); //limpa o mapa
for (int x=1; x<columns-1; x++) //loop navega pelas colunas
{
for (int y=1; y<rows-1; y++)
{
gridPosition.Add (new Vector2(x,y));
}
}
}
void BoardSetup ()
{
//starta o mapa e atribui o transform
boardHolder = new GameObject ("Board").transform;
for (int x=-1; x<columns+1; x++)
{
for (int y=-1; y<rows+1; y++)
{
//seleciona um tile para aplicar no mapa
GameObject toInstantiate = floorTiles(Random.Range(0,floorTiles.Length));
//verifica se e muro externo
if (x == -1 || y == -1 || x == columns || y == rows)
{
toInstantiate = outerWallTiles(Random.Range(0,outerWallTiles.Length));
}
GameObject instance = Instantiate (toInstantiate, new Vector2(x,y), Quaternion.identity) as GameObject;
instance.transform.SetParent (boardHolder);
}
}
}
//retorna valor para grid position
Vector2 RandomPosition()
{
int randomIndex = Random.Range (0, gridPosition.Count);
Vector2 randomPosition = gridPosition (randomIndex);
gridPosition.RemoveAt (randomIndex);
return randomPosition;
}
void LayoutObjectAtRandom(GameObject[] tileArray, int minimum, int maximum)
{
int objectCount = Random.Range (minimum, maximum);
for (int i = 0; i < objectCount; i++)
{
Vector3 randomPosition = RandomPosition();
GameObject tileChoice = tileArray(Random.Range(0,tileArray.Length));
Instantiate(tileChoice, randomPosition, Quaternion.identity);
}
}
public void SetupScene (int Level)
{
BoardSetup (); //starta o mapa
initialiseList (); //starta o grid
//instancia numeros aleatorios de muros internos
LayoutObjectAtRandom (wallTiles, wallCount.minimum, wallCount.maximum);
//instancia o numero aleatorio de comida
LayoutObjectAtRandom (foodTiles, foodCount.minimum, foodCount.maximum);
//seta o numero de enemys baseado no lvl
int enemyCount = (int)Mathf.Log (Level, 2f);
LayoutObjectAtRandom (enemyTiles, enemyCount, enemyCount);
//
Instantiate (exit, new Vector2 (columns-1, rows-1), Quaternion.identity);
}
}