Пример #1
0
    private void CheckInput()
    {
        float missedShot = 0.0f;

        if (shotMade && InputMgr.IsAnyResetButtonDown())
        {
            ball.gameObject.transform.SetPositionAndRotation(ballStartPosition, Quaternion.identity);
            ballRb.velocity = Vector3.zero;
            goalkeeper.gameObject.transform.SetPositionAndRotation(goalkeeperStartPosition, Quaternion.identity);
            goalkeeper.gameObject.transform.Rotate(Vector3.up, 180.0f);
            shotForce            = minShotForce;
            wallCollider.enabled = false;
            joy1Shooting         = !joy1Shooting;
            goalScored           = false;
            shotMade             = false;

            if (!joy1Shooting && shotMade)
            {
                round++;
            }
        }

        if (InputMgr.IsShotButtonHeld(joy1Shooting))
        {
            shotForce += 0.15f;

            if (shotForce > maxShotForce)
            {
                shotForce = maxShotForce;
            }
        }

        if (InputMgr.IsShotButtonUp(joy1Shooting))
        {
            Vector3 shotVector;
            Vector3 saveVector;
            String  footballerHorizontal;
            String  footballerVertical;
            String  goalkeeperHorizontal;
            String  goalkeeperVertical;

            shotMade = true;

            if (shotForce > maxGoalShotForce)
            {
                missedShot = (shotForce - maxGoalShotForce) / 10.0f;

                if (missedShot < 0.1f)
                {
                    missedShot = 0.1f;
                }
            }

            if (joy1Shooting)
            {
                footballerHorizontal = InputMgr.Joy1Horizontal;
                footballerVertical   = InputMgr.Joy1Vertical;
                goalkeeperHorizontal = InputMgr.Joy2Horizontal;
                goalkeeperVertical   = InputMgr.Joy2Vertical;
            }
            else
            {
                footballerHorizontal = InputMgr.Joy2Horizontal;
                footballerVertical   = InputMgr.Joy2Vertical;
                goalkeeperHorizontal = InputMgr.Joy1Horizontal;
                goalkeeperVertical   = InputMgr.Joy1Vertical;
            }

            shotVector = FootballerAction(footballerHorizontal, footballerVertical, missedShot);
            ballRb.AddForce(shotVector * shotForce, ForceMode.Impulse);
            saveVector = GoalkeeperAction(goalkeeperHorizontal, goalkeeperVertical);
            goalkeeperRb.AddForce(saveVector * 250.0f, ForceMode.Impulse);
        }
    }