コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.E))
        {
            Destroy(GameObject.Find("PlayerSelectionData"));
            SceneManager.LoadScene("GameScene");
        }

        // Get the inputdevice that was most recently pressed
        InputDevice currentInput = InputManager.ActiveDevice;


        bool alreadyActive = false;



        // If X was pressed
        if (currentInput.Action1.WasPressed)
        {
            // Check to see if this player is already active
            foreach (PlayerSelection plr in players)
            {
                if (plr.input.GUID == currentInput.GUID)
                {
                    alreadyActive = true;
                }
            }

            // Don't add any more than 4 players
            if (players.Count >= 4)
            {
                alreadyActive = true;
            }

            if (!alreadyActive)
            {
                // Add the new player
                PlayerSelection newPlr = new PlayerSelection
                {
                    playerType = PlayerType.UNDECIDED,
                    input      = currentInput
                };

                GameObject playerCursor = GameObject.Find((playerCount + 1).ToString());
                Color      cursorColour = playerCursor.GetComponent <Image>().color;
                cursorColour.a = 1;

                CursorScript cursorScript = playerCursor.GetComponent <CursorScript>();
                playerCursor.GetComponent <Image>().color = cursorColour;

                cursorScript.player = newPlr;
                cursorScript.Yeet();
                cursorScript.playerNumber = playerCount;

                playerCursor.transform.SetParent(transform); // pull the cursor out of the playerindicator gameobject
                players.Add(newPlr);
                playerCount++;

                RefreshPlayerAvailabilities();
            }
        }


        if (readyToStart)
        {
            // If start button was pressed, start the game
            if (currentInput.Command.WasPressed && !starting)
            {
                starting = true;

                PreparePlayerSelectionObject();
                SceneManager.LoadScene("GameScene");
            }
        }
    }