// Update is called once per frame
    void Update()
    {
        if (!UIManager.instance.GetIsPaused())//일시정지 상태가 아닐때
        {
            if (UIManager.instance.isReadParchment && Input.GetKeyDown(KeyCode.E) && !ParchmentControll.instance.GetIsPlayingDocumentAnim())
            {
                if (GameManager.instance.GetPlayState() == GameManager.PlayState.Act)
                {
                    UIManager.instance.isFading = true;
                    DocumentControll.instance.ResetDocumentOfAndren();

                    if (CheckEventCodeFromPlayedEventList("224") && ParchmentControll.instance.GetIsActivated_Help_Of_Andren() &&
                        ((NumOfAct.Equals("53") && TimeSlot.Equals("74")) || (NumOfAct.Equals("54") && TimeSlot.Equals("79"))))
                    {
                        DocumentControll.instance.GetAndrenClue(NumOfAct);  // 안드렌이 모은 단서 획득
                        UIManager.instance.SetIsReadParchment_In_74_79(false);
                    }

                    //Debug.Log("단서 정리 시스템 종료");
                    UIManager.instance.ArrangeClue();

                    if (NumOfAct.Equals("54") && TimeSlot.Equals("79"))
                    {
                        UIManager.instance.isReadParchment = false;
                        StartCoroutine(UIManager.instance.FadeEffectForChoiceEnding());
                        return;
                    }

                    //단서 정리 시스템을 종료 한 후, 화면이 Fade in 되고 "~시간대가 지났다" 라는 텍스트 출력 후, 같이 Fade out되고 시간대 변경
                    StartCoroutine(UIManager.instance.FadeEffectForChangeTimeSlot());
                }
                else if (GameManager.instance.GetPlayState() == GameManager.PlayState.Tutorial)
                {
                    TutorialManager.instance.isParchmentTutorial = false;

                    UIManager.instance.ArrangeClue();
                }

                UIManager.instance.isReadParchment = false;
            }

            //if (Input.GetMouseButtonDown(0))
            //{
            //    Debug.Log(UIManager.instance.GetIsOpenedParchment() + ", " + UIManager.instance.isFading + ", " + UIManager.instance.GetIsOpenNote() + ", " + UIManager.instance.isPortaling + ", " + MiniMapManager.instance.IsMiniMapOpen() + ", " + isNearObject);
            //}

            if (Input.GetKeyDown(KeyCode.Escape) && !UIManager.instance.GetIsReadParchment_In_74_79())
            {
                // 양피지 비활성화
                UIManager.instance.SetActiveFalseToParchment();
                DocumentControll.instance.ResetDocumentOfAndren();
            }

            /* 오브젝트와의 상호작용을 위한 if */
            if (Input.GetMouseButtonDown(0) && CheckCondition_InteractionObject() && !UIManager.instance.GetStateDiary())
            {
                pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                ray = new Ray2D(pos, Vector2.zero);
                hit = Physics2D.Raycast(ray.origin, ray.direction);

                if (hit.collider == null)
                {
                    //Debug.Log("아무것도 안맞죠?");
                }
                else if ((hit.collider.tag == "MerteDesk" || hit.collider.tag == "InteractionObject"))// && GameManager.instance.GetPlayState() != GameManager.PlayState.Ending)
                {
                    if (hit.collider.name.Equals("책상_메르테 사무실"))
                    {
                        if (!UIManager.instance.isReadParchment && !TutorialManager.instance.isPlayingEndTutorial)
                        {
                            // 메르테 책상 강조 종료 및 다음 대화 출력 트리거
                            if (GameManager.instance.GetPlayState() == GameManager.PlayState.Tutorial && !TutorialManager.instance.isCompletedTutorial[21])
                            {
                                TutorialManager.instance.isCompletedTutorial[21] = true;
                                TutorialManager.instance.isParchmentTutorial     = false;
                            }

                            //Debug.Log("단서 정리 시스템 활성화");
                            UIManager.instance.SetDocumentControll(true);
                            // 양피지 갱신
                            ParchmentControll.instance.UpdateParchmentPosition(playerClueLists_In_Certain_Timeslot.Count);

                            if (ParchmentControll.instance.GetParchmentPosition().y != ParchmentControll.instance.min_Scroll_Position_Parchment)
                            {
                                ParchmentControll.instance.SetParchmentPosition(new Vector2(0, ParchmentControll.instance.min_Scroll_Position_Parchment));
                            }

                            //if (ParchmentControll.instance.GetAggregationClueListScrollListPosition().y != -720)
                            //    ParchmentControll.instance.SetAggregationClueListScrollListPosition(new Vector2(0, -720));

                            if (ParchmentControll.instance.GetHelperContentPosition().y != 0)
                            {
                                ParchmentControll.instance.SetHelperContentPosition(new Vector2(0, 0));
                            }

                            UIManager.instance.ArrangeClue();
                        }
                        else
                        {
                            //Debug.Log("단서 정리 시스템 활성화 실패");
                        }
                    }
                    else
                    {
                        if (GameManager.instance.GetPlayState() == GameManager.PlayState.Act)
                        {
                            if (DialogManager.instance.CheckInteraction(hit.collider.name))
                            {
                                //Debug.Log("hit.collider.name : " + npcParser.GetNpcCodeFromName(hit.collider.name));
                                //try
                                //{
                                //    Debug.Log("사건" + NumOfAct + "의 " + TimeSlot + "시간대에서 " + hit.collider.name + "과 대화시도");
                                //    DialogManager.instance.InteractionWithObject(npcParser.GetNpcCodeFromName(hit.collider.name));
                                //}
                                //catch
                                //{
                                //    Debug.Log("사건" + NumOfAct + "의 " + TimeSlot + "시간대에서 " + hit.collider.name + "과 대화 중 오류 발생");
                                //}

                                Debug.Log("사건" + NumOfAct + "의 " + TimeSlot + "시간대에서 " + hit.collider.name + "( + " + npcParser.GetNpcCodeFromName(hit.collider.name) + ")과 대화시도");
                                DialogManager.instance.InteractionWithObject(npcParser.GetNpcCodeFromName(hit.collider.name));
                            }
                        }
                        else if (GameManager.instance.GetPlayState() == GameManager.PlayState.Tutorial)
                        {
                            if (hit.collider.name.Equals("시체_튜토리얼") && !TutorialManager.instance.isCompletedTutorial[4])
                            {
                                TutorialManager.instance.isCompletedTutorial[3] = true;
                                TutorialManager.instance.isCompletedTutorial[4] = true;
                                //DialogManager.instance.InteractionWithObject("905");

                                TutorialManager.instance.InvokeTutorial();
                                //TutorialManager.instance.IncreaseTutorial_Index();

                                TutorialManager.instance.TagChange(0, "Untagged");
                            }

                            if (hit.collider.name.Equals("식탁_레이나 집") && !TutorialManager.instance.isCompletedTutorial[6])
                            {
                                TutorialManager.instance.isCompletedTutorial[5] = true;
                                TutorialManager.instance.isCompletedTutorial[6] = true;
                                //DialogManager.instance.InteractionWithObject("907");

                                TutorialManager.instance.InvokeTutorial();
                                //TutorialManager.instance.IncreaseTutorial_Index();

                                TutorialManager.instance.TagChange(1, "Untagged");
                            }

                            if (hit.collider.name.Equals("싱크대_레이나 집") && !TutorialManager.instance.isCompletedTutorial[8])
                            {
                                TutorialManager.instance.isCompletedTutorial[7] = true;
                                TutorialManager.instance.isCompletedTutorial[8] = true;
                                //DialogManager.instance.InteractionWithObject("909");

                                TutorialManager.instance.InvokeTutorial();
                                //TutorialManager.instance.IncreaseTutorial_Index();

                                TutorialManager.instance.TagChange(2, "Untagged");
                            }

                            if (hit.collider.name.Equals("바륀") && !TutorialManager.instance.isCompletedTutorial[11])
                            {
                                TutorialManager.instance.isCompletedTutorial[9]  = true;
                                TutorialManager.instance.isCompletedTutorial[11] = true;
                                //TutorialManager.instance.IncreaseTutorial_Index();
                                //TutorialManager.instance.isCompletedTutorial[11] = true;
                                //DialogManager.instance.InteractionWithObject("912");

                                TutorialManager.instance.InvokeTutorial();
                                //TutorialManager.instance.IncreaseTutorial_Index();

                                TutorialManager.instance.TagChange(3, "Untagged");
                            }
                        }// if-else PlayState
                        else if (GameManager.instance.GetPlayState() == GameManager.PlayState.Ending)
                        {
                            if (DialogManager.instance.CheckInteraction(hit.collider.name) && !UIManager.instance.isConversationing)
                            {
                                Debug.Log("사건" + NumOfAct + "의 " + TimeSlot + "시간대에서 " + hit.collider.name + "( + " + npcParser.GetNpcCodeFromName(hit.collider.name) + ")과 대화시도");

                                if (hit.collider.name.Equals("금고_주인공사무실"))
                                {
                                    // 일기장을 얻었다는 대화가 끝난 후, 일기장 활성화 시키기
                                    DialogManager.instance.InteractionWithObject("getDiary");
                                }
                                else
                                {
                                    // 금고가 아닌 다른 오브젝트와 상호작용 시
                                    DialogManager.instance.InteractionWithObject("findUsingKey");
                                }
                            }
                        }
                    } // if-else hit 책상
                }     // if-else hit null
            }         // if-else GetMouseButtonDown
        }             // if GetIsPaused
    }
    void Start()
    {
        if (GameManager.instance.GetPlayState() == GameManager.PlayState.Ending)
        {
            if (GameManager.instance.GetEndingState() == GameManager.EndingState.True)
            {
                // 제렐을 플레이어로 만들고, 메르테 비활성화
                Vector3 mertePosition = GetPlayerPosition();
                merte.SetActive(false);
                andren.SetActive(true);
                SetPlayer(andren);
                SetPlayerPosition(mertePosition); // 제렐을 메르테의 원래 자리로 변경
            }
        }

        if (GameManager.instance.GetGameState().Equals(GameManager.GameState.NewGame_Loaded))
        {
            NumOfAct = "53";   //사건3 시작
            TimeSlot = "71";   //첫째주 시작

            if (GameManager.instance.GetPlayState() == GameManager.PlayState.Tutorial)
            {
                UIManager.instance.act3Button.SetActive(false);
            }
            UIManager.instance.act4Button.SetActive(false);
            UIManager.instance.act5Button.SetActive(false);

            checkNumOfAct = NumOfAct;
            checkTimeSlot = TimeSlot;

            //DialogManager.instance.SetLists();
            ItemDatabase.instance.SetLists();
        }
        else if (GameManager.instance.GetGameState().Equals(GameManager.GameState.PastGame_Loaded))
        {
            NumOfAct = "";
            TimeSlot = "";

            //DialogManager.instance.SetLists();
            ItemDatabase.instance.SetLists();
            GameManager.instance.LoadPlayerData();
            eventVariable = GameManager.instance.GetEventVariable();
            //GameManager.instance.SetEventVariable(ref GetEventVariableClass());

            if (NumOfAct.Equals("53"))
            {
                UIManager.instance.act4Button.SetActive(false);
                UIManager.instance.act5Button.SetActive(false);
            }
            else if (NumOfAct.Equals("54"))
            {
                UIManager.instance.SetNameOfCase("사건4 연쇄살인 4번째 피해자_륑 에고이스모");
                UIManager.instance.act4Button.SetActive(true);
                UIManager.instance.act5Button.SetActive(false);
            }
            else if (NumOfAct.Equals("55"))
            {
                UIManager.instance.SetNameOfCase("사건4 연쇄살인 4번째 피해자_륑 에고이스모");
                UIManager.instance.act4Button.SetActive(true);
                UIManager.instance.act5Button.SetActive(true);
            }

            checkNumOfAct = NumOfAct;
            checkTimeSlot = TimeSlot;

            ResetClueList_In_Certain_Timeslot(); // for PlaySaveGame

            EventManager.instance.PlayEvent();
        }
    }