private void OnJoinGame(CallbackContext ctx) { if (InputDeviceManager.AddPlayer(ctx.control.device)) { int playerNumber = InputDeviceManager.GetPlayerNumber(ctx.control.device); playerProps[playerNumber - 1].SetActive(true); playerTexts[playerNumber - 1].SetActive(false); Debug.Log("Player " + playerNumber + " joined game"); } }
private void SpawnPlayers() { int playerCount = InputDeviceManager.GetCurrentPlayerCount(); //If no current players, use the default if (playerCount == 0 && defaultPlayer != null) { int playerIndex = 0; if (Gamepad.current != null) { InputDeviceManager.AddPlayer(Gamepad.current.device); } defaultPlayer.GetComponent <PlayerInputController>().SetPlayerIndex(playerIndex); defaultPlayer.transform.position = playerSpawns[0].position; } else { if (defaultPlayer != null) { Destroy(defaultPlayer); } int maxPlayers = InputDeviceManager.GetMaxPlayerCount(); for (int i = 0; i < maxPlayers; i++) { if (InputDeviceManager.GetPlayerDevice(i) != null) { int playerIndex = i; GameObject tempPlayer = PlayerInput.Instantiate(playerPrefab, playerIndex, "Gamepad", -1, InputDeviceManager.GetPlayerDevice(playerIndex)).gameObject; tempPlayer.gameObject.GetComponent <PlayerInputController>().SetPlayerIndex(playerIndex); Transform playerObj = tempPlayer.transform.root; playerObj.position = playerSpawns[i].position; playerObj.parent = playerContainer; } } } }