Example #1
0
        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 = IncontrolPlayerActions.CreateWithJoystickBindings();
                    actions.Device = inputDevice;

                    player.Actions = actions;
                }

                players.Add(player);

                return(player);
            }

            return(null);
        }
Example #2
0
 void OnEnable()
 {
     InputManager.OnDeviceDetached += OnDeviceDetached;
     keyboardListener = IncontrolPlayerActions.CreateWithKeyboardBindings();
     joystickListener = IncontrolPlayerActions.CreateWithJoystickBindings();
 }