示例#1
0
    void Update()
    {
        playerOneScore.text = player1Score.ToString();              // Update player 1 score
        playerTwoScore.text = player2Score.ToString();              // Update player 2 score

        if (ball.transform.position.x >= rightBounds)               // Check if ball has passed the right hand side of the screen
        {
            AudioManager.instance.PlaySFXOneShot(loseSound);        // Play the lose sound effect
            player1Score++;                                         // Increase player 1 score
            leftPaddle.ResetPaddle();                               // Reset the left paddle
            rightPaddle.ResetPaddle();                              // Reset the right paddle
            ball.RespawnBall();                                     // Reset the ball
        }

        if (ball.transform.position.x <= leftBounds)                // Check if ball has passed the left hand side of the screen
        {
            AudioManager.instance.PlaySFXOneShot(loseSound);
            player2Score++;
            leftPaddle.ResetPaddle();
            rightPaddle.ResetPaddle();
            ball.RespawnBall();
        }
    }