Player CreatePlayer(InputDevice inputDevice) { if (players.Count < maxPlayers) { // Pop a position off the list. We'll add it back if the player is removed. var playerPosition = playerPositions[0]; playerPositions.RemoveAt(0); var gameObject = (GameObject)Instantiate(playerPrefab, playerPosition, Quaternion.identity); var player = gameObject.GetComponent <Player>(); if (inputDevice == null) { // We could create a new instance, but might as well reuse the one we have // and it lets us easily find the keyboard player. player.Actions = keyboardListener; } else { // Create a new instance and specifically set it to listen to the // given input device (joystick). var actions = PlayerActions.CreateWithJoystickBindings(); actions.Device = inputDevice; player.Actions = actions; } players.Add(player); return(player); } return(null); }
void OnEnable() { spawnPoses[0] = playerPositions[0].position; spawnPoses[1] = playerPositions[1].position; InputManager.OnDeviceDetached += OnDeviceDetached; keyboardListener = PlayerActions.CreateWithKeyboardBindings(); joystickListener = PlayerActions.CreateWithJoystickBindings(); }
private Player CreatePlayer(InputDevice inputDevice) { if (players.Count < 4) { Vector3 position = playerPositions[0]; playerPositions.RemoveAt(0); GameObject gameObject = Object.Instantiate(playerPrefab, position, Quaternion.identity); Player component = gameObject.GetComponent <Player>(); if (inputDevice == null) { component.Actions = keyboardListener; } else { PlayerActions playerActions = PlayerActions.CreateWithJoystickBindings(); playerActions.Device = inputDevice; component.Actions = playerActions; } players.Add(component); return(component); } return(null); }
void OnEnable() { InputManager.OnDeviceDetached += OnDeviceDetached; keyboardListener = PlayerActions.CreateWithKeyboardBindings(); joystickListener = PlayerActions.CreateWithJoystickBindings(); }