Пример #1
0
    //We only do this if absolutely necessary
    public void UpdateContinents()
    {
        //Before we do anything, check if any people need to be destroyed
        peopleManager.CheckKillPeople();

        //Whenever anything about the maps change, we delete these copies and instantiate new versions in their place
        Vector3 cont1Pos       = _continents1.transform.position;
        Vector3 cont2Pos       = _continents2.transform.position;
        Vector3 contForwardPos = _continentsForward.transform.position;

        //Destroy the old versions
        Destroy(_continents1);
        Destroy(_continents2);
        Destroy(_continentsForward);

        //Instantiate the new versions and move them into position
        _continents1       = Instantiate(continentsMain, worldMapParent);
        _continents2       = Instantiate(continentsMain, worldMapParent);
        _continentsForward = Instantiate(continentsMain, worldMapParent);
        _continents1.transform.position       = cont1Pos;
        _continents2.transform.position       = cont2Pos;
        _continentsForward.transform.position = contForwardPos;

        //Instantiate the continents and see if we need to swap players
        _continents1.GetComponent <ContinentManager>().InstantiateNewContinent(continentsMain.GetComponent <ContinentManager>().lines);
        _continents2.GetComponent <ContinentManager>().InstantiateNewContinent(continentsMain.GetComponent <ContinentManager>().lines);
        _continentsForward.GetComponent <ContinentManager>().InstantiateNewContinent(continentsMain.GetComponent <ContinentManager>().lines);

        //Set our current continent
        if (_curCont1)
        {
            curContinent = _continents1;
        }
        else
        {
            curContinent = _continents2;
        }

        //Send a reference of the current player to the Connection Manager
        //connectionManager.currentPlayer = curContinent.GetComponent<ContinentManager>().player;

        //Send references of our new players to PeopleManager
        peopleManager.player1 = _continents1.transform.Find("Player").gameObject;
        peopleManager.player2 = _continents2.transform.Find("Player").gameObject;

        //Send a reference of our currently active player
        if (peopleManager.player1Active)
        {
            connectionManager.currentPlayer = peopleManager.player1;
        }
        else
        {
            connectionManager.currentPlayer = peopleManager.player2;
        }

        //Make sure the line to the mouse pointer is still being drawn if it needs to be
        lineDraw.DrawLineToMousePointer();
    }
Пример #2
0
    //Check if the current player has moved far enough off the screen to swap to the other player
    public void SwapPlayer(GameObject cont1, GameObject cont2)
    {
        float player1Dist = Vector3.Distance(player1.transform.position, Camera.main.transform.position);
        float player2Dist = Vector3.Distance(player2.transform.position, Camera.main.transform.position);

        //Check the relevant player and see if their distance from the camera transform is further than the other point
        if (player1Active & player1Dist > player2Dist)
        {
            //Deactivate the old line
            connectionManager.currentPlayer.GetComponent <LineRenderer>().enabled = false;

            //Set the new currentPlayer
            connectionManager.currentPlayer = cont2.transform.Find("Player").gameObject;
            Debug.Log("Swapped to player 2 at " + connectionManager.currentPlayer);
            player1Active = false;
        }
        else if (!player1Active & player2Dist > player1Dist)
        {
            //Deactivate the old line
            connectionManager.currentPlayer.GetComponent <LineRenderer>().enabled = false;

            //Set the new currentPlayer
            connectionManager.currentPlayer = cont1.transform.Find("Player").gameObject;
            Debug.Log("Swapped to player 1 at " + connectionManager.currentPlayer);
            player1Active = true;
        }

        //We just swapped players, so tell LineDraw to do its thing if necessary
        lineDraw.DrawLineToMousePointer();
    }