Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (gameState >= 0)
        {
            var emission = goalParticle.emission;
            emission.enabled = false;
            // Goal particle emission
            if (emissionTimer > 0.0f)
            {
                emission.enabled = true;
                emissionTimer -= Time.deltaTime;
            }

            // Game control
            if (gameState == 0 && !scoreUI.IsGameEnd())
            {
                scoreUI.showStartPrompt = true;
                bool space = Input.GetKey("space");
                if (space)
                {
                    gameState = 1;
                    puck.GetComponent<Puck>().SetStartVelocity();
                    scoreUI.showStartPrompt = false;
                    if (gameRound == 0)
                    {
                        soundEffects.PlayOneShot(pongStart);
                    }
                }
            }
            else if (!playedEndSound && scoreUI.IsGameEnd())
            {
                playedEndSound = true;
                if (scoreUI.IsWin())
                {
                    soundEffects.PlayOneShot(pongGameOverWin);
                }
                else
                {
                    soundEffects.PlayOneShot(pongGameOverLose);
                }
            }
            else if (scoreUI.IsGameEnd())
            {
                bool space = Input.GetKey("space");
                if (space)
                {
                    scoreUI.showStartPrompt = false;
                    gameRound = 0;
                    this.RestartGameState();
                    puck.GetComponent<Puck>().ResetVelocity();
                    puck.GetComponent<Puck>().SetStartVelocity();
                    scoreUI.scorePlayer = 0;
                    scoreUI.scorePlayerAI = 0;
                    if (gameRound == 0)
                    {
                        soundEffects.PlayOneShot(pongStart);
                    }
                }
            }
        }
    }