/// <summary>
 /// Given a side, the side's objective gameObject will be chosen at random from the list
 /// </summary>
 /// <param name="side"></param>
 private void PickRandomObjectiveObject(ObjectiveSide side)
 {
     if (side == ObjectiveSide.Left)
     {
         SetObjectiveGameObject(leftObjectives[Random.Range(0, leftObjectives.Count)], ObjectiveSide.Left);
     }
     else if (side == ObjectiveSide.Right)
     {
         SetObjectiveGameObject(rightObjectives[Random.Range(0, rightObjectives.Count)], ObjectiveSide.Right);
     }
 }
 /// <summary>
 /// Sets what gameObjective the current objective is for a given side
 /// </summary>
 /// <param name="gameObjectToSetAsObjective"></param>
 /// <param name="side"></param>
 public void SetObjectiveGameObject(GameObject gameObjectToSetAsObjective, ObjectiveSide side)
 {
     if (side == ObjectiveSide.Left)
     {
         leftSideObjective = gameObjectToSetAsObjective;
     }
     else if (side == ObjectiveSide.Right)
     {
         rightSideObjective = gameObjectToSetAsObjective;
     }
     else if (side == ObjectiveSide.Both)
     {
         leftSideObjective  = gameObjectToSetAsObjective;
         rightSideObjective = gameObjectToSetAsObjective;
     }
 }
    /// <summary>
    /// Updates currentObjectiveSide and enables that side's objective
    /// </summary>
    /// <param name="side"></param>
    public void ActivateObjective(ObjectiveSide side)
    {
        if (side == ObjectiveSide.Left)
        {
            currentObjectiveSide = ObjectiveSide.Left;
            PickRandomObjectiveObject(ObjectiveSide.Left);
            ToggleObjective(leftSideObjective, true);

            ToggleObjective(rightSideObjective, false);

            playerOneCamera.playerUI.ChangeInstructions("Objective\nActive");
        }
        else if (side == ObjectiveSide.Right)
        {
            currentObjectiveSide = ObjectiveSide.Right;
            PickRandomObjectiveObject(ObjectiveSide.Right);
            ToggleObjective(rightSideObjective, true);

            ToggleObjective(leftSideObjective, false);

            playerTwoCamera.playerUI.ChangeInstructions("Objective\nActive");
        }
        else if (side == ObjectiveSide.Both)
        {
            currentObjectiveSide = ObjectiveSide.Both;
            //PickRandomObjectiveObject(ObjectiveSide.Left);
            ToggleObjective(leftSideObjective, true);

            //PickRandomObjectiveObject(ObjectiveSide.Right);
            ToggleObjective(rightSideObjective, true);
        }
        else if (side == ObjectiveSide.None)
        {
            currentObjectiveSide = ObjectiveSide.None;
            FinishObjective(ObjectiveSide.Both, false, false, false);

            ToggleObjective(leftSideObjective, false);
            ToggleObjective(rightSideObjective, false);
        }
    }
    /// <summary>
    /// Starts the Objective gameplay at a given side or random
    /// </summary>
    /// <param name="side"></param>
    private void StartObjectives(ObjectiveSide side) //Both = Random Side
    {
        if (side == ObjectiveSide.Left)
        {
            ActivateObjective(ObjectiveSide.Left);
        }
        else if (side == ObjectiveSide.Right)
        {
            ActivateObjective(ObjectiveSide.Right);
        }
        else if (side == ObjectiveSide.Both)
        {
            int randomSide = Random.Range(0, 2);

            if (randomSide == 0)
            {
                ActivateObjective(ObjectiveSide.Left);
            }
            else
            {
                ActivateObjective(ObjectiveSide.Right);
            }
        }
    }
    /// <summary>
    /// Removes an objective from a given side and can increment the score, cause fanfare, and automatically switch Objective sides
    /// </summary>
    /// <param name="side"></param>
    /// <param name="incrementScore"></param>
    /// <param name="automaticallySwitchSides"></param>
    public void FinishObjective(ObjectiveSide side, bool incrementScore, bool playFanfare, bool automaticallySwitchSides)
    {
        if (side == ObjectiveSide.Left)
        {
            if (leftSideObjective)
            {
                playerOneCamera.playerUI.currentActiveObjective = null;
            }

            if (playFanfare)
            {
                //GameVars.instance.audioManager.PlaySFX(generatorComplete, 0.5f, playerOneCamera.player.transform.position);
            }
        }
        else if (side == ObjectiveSide.Right)
        {
            if (rightSideObjective)
            {
                playerTwoCamera.playerUI.currentActiveObjective = null;
            }

            if (playFanfare)
            {
                //GameVars.instance.audioManager.PlaySFX(generatorComplete, 0.5f, playerTwoCamera.player.transform.position);
            }
        }
        else if (side == ObjectiveSide.Both)
        {
            if (leftSideObjective)
            {
                playerOneCamera.playerUI.currentActiveObjective = null;
            }

            if (rightSideObjective)
            {
                playerTwoCamera.playerUI.currentActiveObjective = null;
            }

            if (playFanfare)
            {
                //GameVars.instance.audioManager.PlaySFX(generatorComplete, 0.3f, playerOneCamera.player.transform.position);
                //GameVars.instance.audioManager.PlaySFX(generatorComplete, 0.3f, playerTwoCamera.player.transform.position);
            }
        }

        if (incrementScore)
        {
            currentScore++;
        }

        if (automaticallySwitchSides)
        {
            if (currentScore < totalScoreBeforeFinalRush)
            {
                if (currentObjectiveSide == ObjectiveSide.Left)
                {
                    ActivateObjective(ObjectiveSide.Right);
                }
                else if (currentObjectiveSide == ObjectiveSide.Right)
                {
                    ActivateObjective(ObjectiveSide.Left);
                }
            }
            else
            {
                if (!isFinalLeftComplete && !isFinalRightComplete)
                {
                    ActivateObjective(ObjectiveSide.None);
                    SetObjectiveGameObject(leftFinalDoor, ObjectiveSide.Left);
                    SetObjectiveGameObject(rightFinalDoor, ObjectiveSide.Right);
                    ActivateObjective(ObjectiveSide.Both);

                    playerOneCamera.playerUI.ChangeInstructions("Get To The Exit!");
                    playerTwoCamera.playerUI.ChangeInstructions("Get To The Exit!");
                }
                else
                {
                    if (isFinalLeftComplete)
                    {
                        //ToggleObjective(leftFinalDoor, false);
                        playerOneCamera.playerUI.ResetTextLayers();
                        playerOneCamera.GetComponent <PlayerCamera>().sideStatus = PlayerCamera.PlayerSideStatus.Paused;
                        AIManager.Instance.KillSideEnemies(AIManager.Instance.leftSideEnemies);
                    }

                    if (isFinalRightComplete)
                    {
                        //ToggleObjective(rightFinalDoor, false);
                        playerTwoCamera.playerUI.ResetTextLayers();
                        playerTwoCamera.GetComponent <PlayerCamera>().sideStatus = PlayerCamera.PlayerSideStatus.Paused;
                        AIManager.Instance.KillSideEnemies(AIManager.Instance.rightSideEnemies);
                    }

                    if (isFinalLeftComplete && isFinalRightComplete)
                    {
                        StartCoroutine(PlayWinScene());
                    }
                }
            }
        }
    }