Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (starting)
        {
            //play the intro voice over
            StartCoroutine(Introduction());
            starting = false;
        }
        //If game is unpaused
        if (playRound)
        {
            //pause and unpause the music
            if (Input.GetKeyDown("m") && paused == false)
            {
                musicSource.GetComponent <AudioSource>().Pause();
                paused = true;
            }
            else if (Input.GetKeyDown("m") && paused == true)
            {
                musicSource.GetComponent <AudioSource>().Play();
                paused = false;
            }


            if (throwScript.jackThrown && !jackThrown)
            {
                //after 4 seconds have passed since throwing
                if (Time.time - throwScript.shotTime > 4)
                {
                    jackThrown = true;
                    //Check all faulty areas for jack
                    foreach (FaultBoxes fault in faultBoxList)
                    {
                        if (fault != faultBoxList[faultBoxList.Count - 1])
                        {
                            if (fault.GetJackFault())
                            {
                                //Faulty throw
                                faultyJack = true;

                                //Reset fault check
                                fault.SetJackFaultFalse();

                                aimAssistScript.ResetAim();
                            }
                        }
                    }
                    //set jack as thrown on this script, create a new ball and tell throw that there is a new ball

                    if (!faultyJack)
                    {
                        if (currentPlayer == 1)
                        {
                            newBall = Instantiate(redBall, player.transform.position + (player.transform.forward * 2), player.transform.rotation);
                            redBalls++;
                        }
                        else if (currentPlayer == 2)
                        {
                            newBall = Instantiate(greenBall, player.transform.position + (player.transform.forward * 2), player.transform.rotation);
                            greenBalls++;
                        }
                        ballList.Add(newBall);
                        //give throwscript the new ball
                        throwScript.setPower(0.0f);
                        throwScript.setBall(newBall);

                        player.transform.eulerAngles = new Vector3(0, 90, 0);

                        //update scoreboard

                        //activate jack camera
                        cameraOverlay.SetActive(false);
                        cameraOverlay2.SetActive(false);

                        splashScreensScript.PlayerTurnPrompt(currentPlayer);
                    }
                }
            }
            //spawn a new ball
            if (!gameOver)
            {
                //If faulty jack throw
                if (faultyJack)
                {
                    //Destroy jack
                    Object.Destroy(jack);

                    //Reset bools
                    throwScript.jackThrown = false;
                    throwScript.ballThrown = false;

                    jackThrown = false;

                    //Reset power
                    throwScript.setPower(0);

                    //Reset player rotation
                    player.transform.eulerAngles = new Vector3(0, 90, 0);

                    //Spawn new jack
                    spawnJack();

                    //Script gets disabled on jack creation - force enable
                    //jack.GetComponent<Collision>().enabled = true;

                    //Reset bool
                    faultyJack = false;
                }
                else
                {
                    spawnBall();
                }
            }

            //10 balls have been thrown
            if (amountOfBalls > 11 && Time.time - throwScript.shotTime > 5)
            {
                if (!gameOver)
                {
                    checkWinner();
                    gameOver = true;
                }

                if (currentRound < maximumRounds)
                {
                    if (Time.time - throwScript.shotTime > 10)
                    {
                        currentRound++;
                        //reload the level
                        reset();
                        //next round
                        StartCoroutine(RoundEnd());
                    }
                }
                else
                {
                    if (player1Score == player2Score)
                    {
                        if (Time.time - throwScript.shotTime > 10)
                        {
                            currentRound++;
                            reset();
                            //next round
                            StartCoroutine(RoundEnd());
                        }
                    }
                    else
                    {
                        if (gameOver && Time.time - throwScript.shotTime > 12)
                        {
                            // reloadScene();
                        }
                    }
                }
            }
        }
    }