Exemplo n.º 1
0
    private void Update()
    {
        if (GameControl.playerID == 1)
        {
            if (transform.position.y < BoardManager.ballBounds.min.y)
            {
                MatchManager.playerScore += 1;
            }
            else if (transform.position.y > BoardManager.ballBounds.max.y)
            {
                MatchManager.computerScore += 1;
            }
        }
        else if (GameControl.playerID == 2)
        {
            if (transform.position.y < BoardManager.ballBounds.min.y)
            {
                MatchManager.computerScore += 1;
            }
            else if (transform.position.y > BoardManager.ballBounds.max.y)
            {
                MatchManager.playerScore += 1;
            }
        }

        if ((transform.position.y < BoardManager.ballBounds.min.y) || (transform.position.y > BoardManager.ballBounds.max.y))
        {
            for (int i = 0; i < paddles.Length; i++)
            {
                paddles[i].GetComponent <PaddleController>().ResetPaddle();
            }

            if (MatchManager.playerScore + MatchManager.computerScore != 0 && (MatchManager.playerScore + MatchManager.computerScore) % 5 == 0)
            {
                MatchManager.ChangeServer();
                MatchManager.displayText    = true;
                MatchManager.changingServer = true;
            }

            gradient = 3f;
            SetBall(MatchManager.server);
            MatchManager.serve = false;
        }

        if (MatchManager.serve && !MatchManager.paused)
        {
            if (xDir == XDir.LEFT && transform.position.x < BoardManager.ballBounds.min.x)
            {
                BoardManager.collideSound.Play();
                xDir = XDir.RIGHT;
            }
            else if (xDir == XDir.RIGHT && transform.position.x > BoardManager.ballBounds.max.x)
            {
                BoardManager.collideSound.Play();
                xDir = XDir.LEFT;
            }
            MoveBall();
        }
    }