Failed My C# Nils Video Script (No Board Manager)

Asked

Viewed 103 times

0

Nils , or someone who knows how to answer me, there are several errors here in my tab of the console , I’m new in this area and this talking about errors with ) ] } and basic programming things! please help me to solve this ! I need a lot.

This is the video Concerning such a C Script#.

Esta é a imagem dos erros que te falei.

and I’ll also send you all the script that I have here .

 using UnityEngine;
    using System; //Atributo serializable - como aparecem as variaveis no inspector e no editor
    using System.Collections.Generic; //usar Lists.
    using Random = UnityEngine.Random; //Gerar numeros aleatorios
    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 columns = 8; //Quantidade de Colunas do Tabuleiro
    public int rows = 8; //linhas no tabuleiro
    public Count wallCount = new Count (5,9); //Quantidade aleatoria de numeros internos
    public Count foodCount = new Count (1,5); //Quantidade aleatoria de comida(Nao irei Utilizar)
    public GameObject exit;
    public GameObject[] floorTiles; //Chao
    public GameObject[] WallTile; //Muros
    public GameObject[] foodTiles; //Comidas
    public GameObject[] enemyTile; //inimigos
    public GameObject[] outerWallsTiles; //Muros Externos

    private Transform boardHolder; //Variavel para pendurar todo mundo do tabuleiro
    private List <Vector3> gridPosition = new List<Vector3>(); //Lista de Possiveis Posiçoes para os tiles


    //Limpar lista do grid e preparar para garar um novo tabuleiro
    void initialiseList()
    {
        //Limpa as posiçoes
        gridPosition.Clear ();

        //loop para navegar as colunas
        for (int x = 1; x < columns -1; x++)
        {
            for(int y = 1; y<rows-1;y++)
            {

                gridPosition.Add(new Vector3(x,y,0f));
            }

        }
    }

    //configurar background e muros externos
    void BoardSetup()
    {
        //inicializa o tabuleiro e atribiu seu transform
        boardHolder = new GameObject ("Board").transform;

        for(int x = -1, x < columns + 1;x++);
        for(int y = -1, y < columns + 1;y++);
                //Pegar tile aleatorio para fazer parte do chao
                GameObject toInstatiate = floorTiles[Random.Range(0,floorTiles.Length)];

                //verificar se e muro externo
        if( x == -1 || y == -1 || x == columns || y == rows );
                {
                    toInstatiate = outerWallsTiles[Random.Range[0,outerWallsTiles.Length]];


                GameObject instance = Instantiate(toInstatiate, new Vector3(x,y,0f),Quaternion.identity)as GameObject;

                instance.transform.SetParent (boardHolder);
                }
    }

    //Rertorna um valor aleatorio da nossa gridposition
    Vector3 RandomPosition()
    {
        int randomIndex = Random.Range (0, gridPosition.Count);

        Vector3 randomPosition = gridPosition [randomIndex];

        gridPosition.RemoveAt (randomIndex);

        return randomPosition;

    }

    //pega o array de objetos que passar, junto com o valor minimo e maximo que voce vai adicionar daaquele numero de objeto.
    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)
    {
        //colocou os quadradinhos do tabuleiro
        BoardSetup ();
        //inicializou o grid
        initialiseList ();

        //instanciar um numero aleatorio de muros internos
        LayoutObjectAtRandom(WallTile wallCount.minimum, wallCount.maximum);

        //instanciar um numero aleatorio de comidas
        LayoutObjectAtRandom (foodTiles, foodCount.minimum, foodCount.maximum);

        //instanciar o numero decimal inimigos baseado No level
        int enemyCount = (int)Mathf.Log(level, 2f);
        LayoutObjectAtRandom (enemyTile, enemyCount, enemyCount);

        //instanciar a saida
        Instantiate (exit, new Vector3 (columns-1,rows-1,0f),Quaternion.identity);

    }


    }


    // Use this for initialization
    void Start () {

    }

I hope Your Reply . Thank you in advance.

1 answer

3

These mistakes must be happening because you are not closing the classe and the namespace correctly.

The codes below this line are not in the scope of classe.

 public int columns = 8; //Quantidade de Colunas do Tabuleiro

From a verified where the opening of your classe is and where the closure lies.

I set the code, take a look at your code and compare with what is below, mainly pay attention to the openings { and closure } of the keys.

using UnityEngine;
using System; //Atributo serializable - como aparecem as variaveis no inspector e no editor
using System.Collections.Generic; //usar Lists.
using Random = UnityEngine.Random; //Gerar numeros aleatorios

public class BoardManager : MonoBehaviour {
    [Serializable]
    public class Count
    {
        public int minimum;
        public int maximum;

        public Count (int min, int max)
        {
            minimum = min;
            maximum = max;
        }

// Você estava fechando a classe nesta linha

        public int columns = 8; //Quantidade de Colunas do Tabuleiro
        public int rows = 8; //linhas no tabuleiro
        public Count wallCount = new Count (5,9); //Quantidade aleatoria de numeros internos
        public Count foodCount = new Count (1,5); //Quantidade aleatoria de comida(Nao irei Utilizar)
        public GameObject exit;
        public GameObject[] floorTiles; //Chao
        public GameObject[] WallTile; //Muros
        public GameObject[] foodTiles; //Comidas
        public GameObject[] enemyTile; //inimigos
        public GameObject[] outerWallsTiles; //Muros Externos

        private Transform boardHolder; //Variavel para pendurar todo mundo do tabuleiro
        private List <Vector3> gridPosition = new List<Vector3>(); //Lista de Possiveis Posiçoes para os tiles


        //Limpar lista do grid e preparar para garar um novo tabuleiro
        void initialiseList()
        {
            //Limpa as posiçoes
            gridPosition.Clear ();

            //loop para navegar as colunas
            for (int x = 1; x < columns -1; x++)
            {
                for(int y = 1; y<rows-1;y++)
                {
                    gridPosition.Add(new Vector3(x,y,0f));
                }
            }
        }

        //configurar background e muros externos
        void BoardSetup()
        {
            //inicializa o tabuleiro e atribiu seu transform
            boardHolder = new GameObject ("Board").transform;

            for(int x = -1, x < columns + 1;x++);
            for(int y = -1, y < columns + 1;y++);

            //Pegar tile aleatorio para fazer parte do chao
            GameObject toInstatiate = floorTiles[Random.Range(0,floorTiles.Length)];

            //verificar se e muro externo
            if( x == -1 || y == -1 || x == columns || y == rows );
            {
                toInstatiate = outerWallsTiles[Random.Range[0,outerWallsTiles.Length]];

                GameObject instance = Instantiate(toInstatiate, new Vector3(x,y,0f),Quaternion.identity)as GameObject;

                instance.transform.SetParent (boardHolder);
            }
        }

        //Rertorna um valor aleatorio da nossa gridposition
        Vector3 RandomPosition()
        {
            int randomIndex = Random.Range (0, gridPosition.Count);

            Vector3 randomPosition = gridPosition [randomIndex];

            gridPosition.RemoveAt (randomIndex);

            return randomPosition;
        }

        //pega o array de objetos que passar, junto com o valor minimo e maximo que voce vai adicionar daaquele numero de objeto.
        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)
        {
            //colocou os quadradinhos do tabuleiro
            BoardSetup ();
            //inicializou o grid
            initialiseList ();

            //instanciar um numero aleatorio de muros internos
            LayoutObjectAtRandom(WallTile wallCount.minimum, wallCount.maximum);

            //instanciar um numero aleatorio de comidas
            LayoutObjectAtRandom (foodTiles, foodCount.minimum, foodCount.maximum);

            //instanciar o numero decimal inimigos baseado No level
            int enemyCount = (int)Mathf.Log(level, 2f);
            LayoutObjectAtRandom (enemyTile, enemyCount, enemyCount);

            //instanciar a saida
            Instantiate (exit, new Vector3 (columns-1,rows-1,0f),Quaternion.identity);
        }

        // e o namespace aqui...

        // Use this for initialization
        void Start () {

        }

    }// fecha a classe
}// fecha o namespace

Always pay attention to those details. Fix this, and see if it works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.