private void Update()
    {
        // Player start input
        if (Input.GetKey(startKey))
        {
            OnPressStart?.Invoke(this, EventArgs.Empty);
        }

        // Player one input
        if (Input.GetKey(playerOneLeftKey))
        {
            OnPlayerOnePressLeft?.Invoke(this, EventArgs.Empty);
        }
        else if (Input.GetKey(playerOneRightKey))
        {
            OnPlayerOnePressRight?.Invoke(this, EventArgs.Empty);
        }

        // Player two input
        if (Input.GetKey(playerTwoLeftKey))
        {
            OnPlayerTwoPressLeft?.Invoke(this, EventArgs.Empty);
        }
        else if (Input.GetKey(playerTwoRightKey))
        {
            OnPlayerTwoPressRight?.Invoke(this, EventArgs.Empty);
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.F1))
     {
         Application.Quit();
     }
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         OnPressStart?.Invoke();
     }
 }
Beispiel #3
0
        private void ProcessInput(List <Touch> touches, InputState state)
        {
            switch (state)
            {
            case InputState.None:
                break;

            case InputState.Press:
                if (touches[0].phase == TouchPhase.Began)
                {
                    OnPressStart?.Invoke(touches[0].position);
                }
                break;

            case InputState.Sliding:
                Vector3 prevPos    = _prevTouches[0].position;
                Vector3 currentPos = touches[0].position;
                OnSlide?.Invoke(prevPos, currentPos);
                break;

            case InputState.Up:
                OnTouchUp?.Invoke(touches[0].position);
                break;

            case InputState.Pinch:
                if (_prevState != InputState.Pinch)
                {
                    return;
                }

                float prevLength    = (_prevTouches[0].position - _prevTouches[1].position).magnitude;
                float currentLength = (touches[0].position - touches[1].position).magnitude;
                OnPinch?.Invoke(Mathf.Abs(prevLength - currentLength));
                break;

            default:
                break;
            }
        }