Unity MonoDevelop says my variables do not exist?

1

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); } }     
asked by anonymous 05.07.2015 / 02:18

1 answer

5

I'm not Nils, but I'll answer your question. This is a community where thousands of users are responding, and Nils is just one of many others. Because of this you should direct your question to everyone, not just him.

But anyway, let's go:

These are arrays:

public GameObject [] floorTiles;
public GameObject [] outerWallTiles;

This is a list:

private List <Vector2> gridPosition = new List<Vector2> (); //lista de posiscoes possiveis no mapa

And this is an array as a parameter:

void LayoutObjectAtRandom(GameObject[] tileArray, int minimum, int maximum)

These are attempts to invoke methods:

GameObject toInstantiate = floorTiles(Random.Range(0,floorTiles.Length));
// ...
toInstantiate = outerWallTiles(Random.Range(0,outerWallTiles.Length));
// ...
Vector2 randomPosition = gridPosition (randomIndex);
// ...
GameObject tileChoice = tileArray(Random.Range(0,tileArray.Length));

However floorTiles , outerWallTiles , gridPosition , and tileArray are not methods, but collections of objects.

I think what you wanted was this:

GameObject toInstantiate = floorTiles[Random.Range(0, floorTiles.Length)];
// ...
toInstantiate = outerWallTiles[Random.Range(0, outerWallTiles.Length)];
// ...
Vector2 randomPosition = gridPosition[randomIndex];
// ...
GameObject tileChoice = tileArray[Random.Range(0, tileArray.Length)];

That is, you used parentheses () instead of [] brackets.

  • Using parentheses after the name of a variable means trying to invoke a method with the name of the variable.
  • Using brackets after an expression that results in an object (and the name of a variable is an expression) means trying to access an object position that should be a list or array.
05.07.2015 / 04:48