Esempio n. 1
0
        private void UpdateKeyboard()
        {
            // Skip if no key was pressed.
            if (!Keyboard.current.anyKey.wasPressedThisFrame)
            {
                return;
            }
            var pressedKey = GetPressedKey();

            // Skip if the key is already used.
            if (pressedKey == Key.None || _controls.Contains(pressedKey))
            {
                return;
            }

            _controls[_currentKey] = pressedKey;
            IgnoreKey(pressedKey);

            switch (_currentKey)
            {
            // Once the jump key is pressed, create a new player.
            case 0:
                var player = SpawnPlayer(_keyboardPrefab);
                _activeKeyboardInput = player.GetComponent <KeyboardInput>();
                _activeKeyboardInput.SetJumpKey(_controls[0]);
                break;

            case 1:
                _activeKeyboardInput.SetLeftKey(_controls[1]);
                break;

            case 2:
                _activeKeyboardInput.SetRightKey(_controls[2]);
                // Clean up after the player.
                _activeKeyboardInput = null;
                _controls            = new Key[3];
                _playerCount++;
                break;
            }
            _inputDisplay.AdvancePrompt(1);
            _nameDisplay.UpdatePlayers();

            _currentKey++;
            _currentKey %= _controls.Length;
        }
Esempio n. 2
0
 private void Awake()
 {
     _rb            = GetComponent <Rigidbody2D>();
     _keyboardInput = GetComponent <KeyboardInput>();
 }