//------NPC 관련 함수 ------

    public void setText(TextAsset Content, TextAsset yes, TextAsset no)

    {

        //text.text = NpcName.text;

        NpcContent = Content;

        NpcYes = yes;

        NpcNo = no;


        if (!isYes)

            StartCoroutine(talking());

    }

    private IEnumerator talking()

    {

        reader = new StringReader(NpcContent.text);



        yield return readText();


        yield return select();

    }


    private IEnumerator select()

    {

        reader = null;

        while (null == reader)

        {

            if (Input.GetKeyDown("y"))

            {

                isYes = true;

                reader = new StringReader(NpcYes.text);

            }

            else if (Input.GetKeyDown("n"))

            {

                reader = new StringReader(NpcNo.text);

            }

            yield return null;

        }


        yield return readText();


        if (isYes) Yes?.Invoke();

        else No?.Invoke();

    }

    // Invoke("함수이름",3f) 3초 뒤에 함수가 실행





    private IEnumerator readText()

    {

        while (true)

        {

            Npctext = reader.ReadLine();

            if (Npctext == null) break;

            NPCTalk.text = Npctext;

            yield return new WaitForSeconds(2f);

        }

    }



 간단히 설명 하면 

각 npc class 가  UIManager.instacne .setText() 로 각 npc가 들고 있는 

text 내용 text , 수락시 text, 거절시 text를 넣어 주고 

UIManager 에게  넣어주고    

talking 코루틴 에서 내용 text를 한줄씩 보여줌 이후

(readtext 가 한줄씩 reader로 text에 2초 마다 넣어주고 null 이면 이면 break 하는함수임)

 select 에서 y,n 선택 하고 유저가 어떤 선택을 했냐에 따라 

y 면 set때 받아온 수락text 를  n이면 거절text를 하고 

이후에 NPC class 마다 가상함수로 yes 면 yes 함수가 실행 되게 

no면 no 함수가 실행 되게 해야 하는데

(NPC class 에는 yes, no 함수가 제작되어 있음 )


근데 같이 일하는 친구가 너무 코드가 비효율적이라는데

아직 빡대갈이라 나는 잘 모르겠음 

제발 좀 도와주세요