示例#1
0
    private void Update()
    {
        if (playerController)
        {
            playerController.enabled = false;
        }

        if (active && player)
        {
            // Confirm selection with attackInput
            if ((Input.GetButtonDown(attackInput + (player.name == "Player1" ? "1" : "2"))) ||
                (GameManager.singleGame && Input.GetButtonDown(attackInput + "2")))
            {
                MinimapController.instances[0].focus = false;
                if (player.name == "Player1")
                {
                    MinimapController.instances[2].focus = false;
                }
                else if (player.name == "Player2")
                {
                    MinimapController.instances[1].focus = false;
                }

                TransportPlayer(exits[activePortals[selectedIndex]]);
                playerCamera.tr = previousCameraTrack;
                playerCamera.playerFocusFactor = previousPlayerFocusFactor;
                playerCamera = null;
                StartCoroutine(ReactivatePlayer());
            }

            // Change selection with horizontalInput
            float selection = Input.GetAxisRaw(horizontalInput + (player.name == "Player1" ? "1" : "2"));
            if (selection == 0f && GameManager.singleGame)
            {
                selection = Input.GetAxisRaw(horizontalInput + "2");
            }

            if ((Input.GetButtonDown(horizontalInput + (player.name == "Player1" ? "1" : "2"))) ||
                (GameManager.singleGame && Input.GetButtonDown(horizontalInput + "2")))
            {
                selectedIndex += (int)Mathf.Sign(selection);
                if (selectedIndex < 0)
                {
                    selectedIndex = activePortals.Count - 1;
                }
                else if (selectedIndex >= activePortals.Count)
                {
                    selectedIndex = 0;
                }
                PreviewSelection();
            }
        }
    }
示例#2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (active && collision.CompareTag("Player") && player == null)
        {
            // A Portal MUST lead to some other Portal
            //Make sure that portalActivePair is in the list of activePortals
            if (portalActivePair != null)
            {
                portalActivePair.gameObject.SetActive(true);
            }

            // update active portal index
            GetActivePortalIndices();

            // store reference to player
            player = collision.gameObject;

            // no exits, bail
            // @TODO: notify user somehow?
            if (activePortals.Count == 0)
            {
                player = null;
                return;
            }
            // if there's only one exit, just go there
            else if (activePortals.Count <= 2) //the second exit is the same portal itself
            {
                TransportPlayer(exits[activePortals[0]]);

                if (player.name == "Player1")
                {
                    Subtitles.AddPlayer1Subtitle("Player Teleported!");
                }
                else if (player.name == "Player2")
                {
                    Subtitles.AddPlayer2Subtitle("Player Teleported!");
                }
            }
            // otherwise start "selection mode"
            else
            {
                // Reset selectionIndex
                selectedIndex = 0;

                // Store inputs and disable player controller
                playerController         = player.GetComponent <PlayerController>();
                attackInput              = playerController.attackInput;
                horizontalInput          = playerController.walkHorizontalInput;
                playerController.enabled = false;

                // Move camera to show portal selection
                playerCamera                   = FindPlayerCamera();
                previousCameraTrack            = playerCamera.tr;
                previousPlayerFocusFactor      = playerCamera.playerFocusFactor;
                playerCamera.playerFocusFactor = 0f;
                PreviewSelection();

                //Minimap Focus and Subtitle
                MinimapController.instances[0].focus = true;
                if (player.name == "Player1")
                {
                    MinimapController.instances[2].focus = true;
                    Subtitles.AddPlayer1Subtitle("Select the Portal");
                }
                else if (player.name == "Player2")
                {
                    MinimapController.instances[1].focus = true;
                    Subtitles.AddPlayer2Subtitle("Select the Portal");
                }
            }
        }
    }