public string[] Sentences;

    public Transform chatTR;

    public GameObject ChatBoxPrefab;

    //public bool ChatCheck;

    //void Update()

    //{

    //    //if(ChatCheck == true)

    //    //{

    //    //    TalkNpc();

    //    //}

    //}

    void TalkNpc()

    {

        GameObject gocopy = Instantiate(ChatBoxPrefab);

        gocopy.GetComponent<ChatSystem>().OnDialogue(Sentences, chatTR);

    }

    private void OnTriggerEnter2D(Collider2D collision)

    {

        if(collision.gameObject.CompareTag("Player"))

        {

            TalkNpc();

        }

    }


현재 이런 코드를 짜서 적용을 시켰음


어떤 기능을 하냐면

플레이어가 이 사물의 트리거와 닿았을때 대화창을띄우는 기능인데

문제는 대화창이 2번 뜸

업데이트에서 실행되는것도 아닌데 대화창이 두번이나 뜨길레 왜이렇게 뜨는건가 한참을 고민해도 잘 모르겠어서 나름 해결법이라고 생각해서


    bool b_check;

    public string[] Sentences;

    public Transform chatTR;

    public GameObject ChatBoxPrefab;

    //public bool ChatCheck;

    //void Update()

    //{

    //    //if(ChatCheck == true)

    //    //{

    //    //    TalkNpc();

    //    //}

    //}

    void TalkNpc()

if(b_check == true)

{

{

            GameObject gocopy = Instantiate(ChatBoxPrefab);

            gocopy.GetComponent<ChatSystem>().OnDialogue(Sentences, chatTR);

        }

}

   

    private void OnTriggerEnter2D(Collider2D collision)

    {

  b_check = true;

        if(collision.gameObject.CompareTag("Player"))

        {

            TalkNpc();

        }

    }

이렇게 하고 OnTriggerExit2d에서는 b_check = false;로도 했어

그런데 왠진 모르겠는데 해도 2번씩 뜨더라고..

혹시 한번만 뜨게 하는 방법 없을까