Esempio n. 1
0
    public void ManageBounce(Vector3 bouncePosition, int hitterId)
    {
        int result = _referee.IsPoint(bouncePosition, hitterId);

        if (result > 0)
        {
            BallLogic.Instance.DeactivateCollisions();
            if (OnPoint(hitterId))
            {
                BallLogic.Instance.DeactivateCollisions();
                _currentSet.ResetCurrentGame();
                if (hitterId == 1)
                {
                    Debug.Log("You win");
                    _gameManagerLogic.EndGame(true);
                }
                else
                {
                    Debug.Log("You lose");
                    _gameManagerLogic.EndGame(false);
                }

                return;
            }
        }
        else if (result < 0)
        {
            BallLogic.Instance.DeactivateCollisions();
            if (_referee.IsOut(bouncePosition))
            {
                AudioManager.Instance.PlaySound((int)SoundId.SOUND_OUT);
            }

            int opponentId = (hitterId % 2) + 1;
            if (OnPoint(opponentId))
            {
                if (opponentId == 1)
                {
                    Debug.Log("You win");
                    _gameManagerLogic.EndGame(true);
                }
                else
                {
                    Debug.Log("You lose");
                    _gameManagerLogic.EndGame(false);
                }
            }
        }

        if (result == 0 && hitterId != 0)
        {
            _referee.SetServing(false);
        }
        _referee.ResetHitters();
    }