Exemplo n.º 1
0
    //Awake is always called before any Start functions
    void Awake()
    {
        //Check if instance already exists
        if (instance == null)
        {
            //if not, set instance to this
            instance        = this;
            movementoptions = Movemment.allmovement;
        }


        //If instance already exists and it's not this:
        else if (instance != this)
        {
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);
        }

        //Sets this to not be destroyed when reloading scene
        DontDestroyOnLoad(gameObject);

        //Get a component reference to the attached BoardManager script
        boardScript = GetComponent <Map_script>();
        //Call the InitGame function to initialize the first level
    }
Exemplo n.º 2
0
    void GenerateRandomGoals()
    {
        randomGoals.Add(startIndex);
        List <int> unsortedRandomGoals = new List <int>();

        for (int i = 0; i < (CheckpointsAmount); i++)
        {
            int randIndex = Random.Range(0, ((boardWidth - 1) * boardLength) - 1);
            unsortedRandomGoals.Add(randIndex);
        }
        unsortedRandomGoals.Sort();
        for (int i = 0; i < (unsortedRandomGoals.Count); i++)
        {
            randomGoals.Add(unsortedRandomGoals[i]);
        }
        bool       keyOrDoor       = true;
        List <int> tempRandomGoals = new List <int>();

        for (int i = 1; i < (randomGoals.Count); i++)
        {
            GameObject instance;
            if (keyOrDoor)
            {
                instance = Instantiate(keyObject, new Vector3(0f, 0f, 0f), Quaternion.identity) as GameObject;
                instance.transform.position = Board[randomGoals[i]].transform.position + Vector3.up;
                keyOrDoor = false;
            }
            else
            {
                instance = Instantiate(doorObject, new Vector3(0f, 0f, 0f), Quaternion.identity) as GameObject;
                instance.transform.position = Board[randomGoals[i]].transform.position;
                tempRandomGoals.Add(randomGoals[i] + boardLength);
                keyOrDoor = true;
            }
            if (i == randomGoals.Count - 1 && (randomGoals[i] < (boardLength * (boardWidth - 1)) || randomGoals[i] > (boardLength * (boardWidth - 2))))
            {
                tempRandomGoals.Add(randomGoals[i] + boardLength);
            }
            waypointList.Add(instance);
        }
        List <int> newRandomGoals = new List <int>();

        for (int i = 0; i < (randomGoals.Count); i++)
        {
            newRandomGoals.Add(randomGoals[i]);
            for (int j = 0; j < (tempRandomGoals.Count); j++)
            {
                if (randomGoals[i] + boardLength == tempRandomGoals[j])
                {
                    newRandomGoals.Add(tempRandomGoals[j]);
                }
            }
        }
        randomGoals.Clear();
        for (int i = 0; i < (newRandomGoals.Count); i++)
        {
            randomGoals.Add(newRandomGoals[i]);
        }
        randomGoals.Add(endIndex);
    }