// Update is called once per frame
    void Update()
    {
        RuntimeManager.StudioSystem.setParameterByName("decrease", envSound);

        if (actionNum >= 14)
        {
            dayUI.SetActive(false);
            feedbackUI.SetActive(false);

            if (!end)
            {
                EndUI.SetActive(true);
            }

            //Deciding Type of Ending
            Ending();



            if (finalCheck == true)
            {
                //get tile numbers from tileInfo
                tileInfo.GetTileTypes();

                //add/subtract appeal based on results
                appealPoints += tileInfo.pathTiles * 5;
                appealPoints += tileInfo.flowerTiles * 15;
                appealPoints -= tileInfo.dirtTiles * 10;

                //grass appeal mess
                if (tileInfo.grassGrassLevel == 0 && tileInfo.grassBugLevel == 0 && tileInfo.grassWaterLevel == 5 && tileInfo.grassBugLevel == 0)
                {
                    appealPoints += tileInfo.grassTiles * 15;
                }

                //add/subtract env based on results
                envPoints += tileInfo.wildGrassTiles * 10;
                envPoints += tileInfo.mossTiles * 5;
                envPoints -= tileInfo.grassTiles * 5;

                //subtract based on water levels
                if (tileInfo.grassWaterLevel <= 0)
                {
                    appealPoints -= tileInfo.grassWaterLevel * 5;
                }
                if (tileInfo.flowerWaterLevel <= 0)
                {
                    appealPoints -= tileInfo.flowerWaterLevel * 5;
                }
                if (tileInfo.mossWaterLevel <= 0)
                {
                    appealPoints -= tileInfo.mossWaterLevel * 5;
                }
                if (tileInfo.wildgrassWaterLevel <= 0)
                {
                    appealPoints -= tileInfo.wildgrassWaterLevel * 5;
                }

                //subtract based on weed levels
                if (tileInfo.grassWeedLevel >= 3)
                {
                    envPoints += 5;

                    if (tileInfo.grassWeedLevel > 5)
                    {
                        appealPoints -= 5;
                    }
                }
                if (tileInfo.flowerWeedLevel >= 3)
                {
                    envPoints += 5;

                    if (tileInfo.flowerWeedLevel > 5)
                    {
                        appealPoints -= 10;
                    }
                }
                if (tileInfo.wildgrassWeedLevel >= 3)
                {
                    envPoints += 5;
                }

                //subtract based on bug level
                if (tileInfo.grassBugLevel >= 3)
                {
                    envPoints += 5;

                    if (tileInfo.grassBugLevel > 5)
                    {
                        appealPoints -= 5;
                    }
                }
                if (tileInfo.flowerBugLevel >= 3)
                {
                    envPoints += 5;

                    if (tileInfo.flowerBugLevel > 5)
                    {
                        appealPoints -= 5;
                    }
                }
                if (tileInfo.mossBugLevel >= 3)
                {
                    envPoints += 5;

                    if (tileInfo.mossBugLevel > 5)
                    {
                        appealPoints -= 5;
                    }
                }
                if (tileInfo.wildgrassBugLevel >= 3)
                {
                    envPoints += 5;

                    if (tileInfo.wildgrassBugLevel > 5)
                    {
                        appealPoints -= 5;
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (firstClick && instructions.gameObject.active)
            {
                firstClick = false;
                instructions.gameObject.SetActive(false);
                actionSelected = false;
            }

            Vector2    mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
            Vector3Int gridPos  = tileMap.WorldToCell(mousePos);

            //code to select action here
            if (GetTileType(gridPos) == "Null")
            {
                actionSelected = false;
                currentAction  = "null";
            }


            //currentAction = "temp";

            //code to perform action here
            if (actionSelected)
            {
                currentTile = GetTileType(gridPos);
                Debug.Log("tile for action picked");

                if (CompatibleAction(currentTile, currentAction))
                {
                    Debug.Log(currentAction + "ed " + currentTile);
                    tileInfo.tileText.gameObject.SetActive(false);

                    if (currentAction == "water")
                    {
                        if (lastAction == "water")
                        {
                            envPoints   += 10;
                            waterPoints -= 10;

                            envSound -= 10;
                        }
                        else if (lastAction == "herb/pest")
                        {
                            envPoints       -= 20;
                            pollutionPoints -= 20;

                            envSound += 25;
                        }

                        envPoints   += 5;
                        waterPoints -= 5;

                        envSound -= 5;
                        //RuntimeManager.PlayOneShot(waterEvent, cam.transform.position);
                    }
                    else if (currentAction == "herb/pest")
                    {
                        envPoints       -= 70;
                        pollutionPoints -= 50;
                        appealPoints    += 25;

                        envSound += 70;

                        if (lastAction == "water")
                        {
                            envPoints       -= 20;
                            pollutionPoints -= 20;

                            envSound += 40;
                        }
                    }
                    else if (currentAction == "weed")
                    {
                        envPoints    += 10;
                        appealPoints += 10;

                        envSound -= 10;
                    }
                    else if (currentAction == "fertilize")
                    {
                        envPoints       -= 10;
                        pollutionPoints -= 15;
                        appealPoints    += 15;

                        RuntimeManager.StudioSystem.setParameterByName("amount", 2f);
                        RuntimeManager.PlayOneShot(fertilizeEvent, cam.transform.position);
                        envSound += 25;
                    }
                    else if (currentAction == "mow")
                    {
                        appealPoints    += 10;
                        pollutionPoints -= 15;

                        envSound += 15;
                    }

                    lastAction = currentAction;

                    actionNum++;

                    feedback.Feedback(currentAction, actionNum, currentTile);

                    //actions have effects on tile info
                    tileInfo.ActionEffects(currentTile, currentAction);

                    //updating tileText gui
                    tileInfo.GetTileInfo(gridPos);

                    //can change the day to update tiles in TileInfoScript
                    if (actionNum % 2 == 1)
                    {
                        tileInfo.dayChange = true;
                        RuntimeManager.PlayOneShot(clockEvent, cam.transform.position);
                    }
                }
            }

            if (envSound < 0)
            {
                envSound = 0;
            }

            if (envSound > 400)
            {
                envSound = 400;
            }
        }

        //Quit the game when ESC is pressed
        if (Input.GetKeyDown("escape"))
        {
            if (end)
            {
                EndUI.SetActive(false);
            }

            pause.SetActive(true);

            pauseSound.start();
        }
    }