자꾸 이런거 물어봐서 미안행... 근데 유니티가 자꾸 멈춘다 이유를 모르겠다.

내가 만들려는거는 오브젝트를 껏다 켰다 하면서 쓰는 보스 스펠 같은건데 한번은 작동이 잘 되는데 두번째 활성화 하면 그 순간 유니티가 멈춤 while문도 안쓰고 혹시몰라서 코루틴도 다 치웠는데 계속 두번째에서 멈춤, 이 스크립트가 문제인건 확실함 이거 끄고 오브젝트 활성화 하면 안멈춤 근데 이 스크립트 키면 멈춤 이유를 모르겠다 제발 도와주라 ㅠㅠ 


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using ND_VariaBULLET;


public class GrabPattern : MonoBehaviour

{

    public List<GameObject> GrapPos = new List<GameObject>(4);

    public List<GameObject> wallObj = new List<GameObject>(4);

    public List<GameObject> StopPos = new List<GameObject>(4);

    public List<GameObject> OriPos = new List<GameObject>(4);

    public List<int> grapNum = new List<int>(4);

    public GameObject Hook;

    public GameObject Boss;

    public GameObject lineCol;

    private int nowgrap = 0;

    private bool grapChk;

    public bool cutChk;

    public float Speed;

    public float pullSpeed;

    public float ws;

    public float ends;


    private void OnEnable()

    {

        cutChk = false;

        nowgrap = 0;

        grapChk = true;

        Hook.transform.position = Boss.transform.position;

        CreateUnDuplicateRandom(0, 4);

    }


    private void Update()

    {

        if (!cutChk)

        {

            if (grapChk)

            {

                Grap();

            }

            else if (!grapChk)

            {

                Pull();

                if (Hook.transform.position == new Vector3(0, 0, 0))

                {

                    CutLine();

                }

            }

        }

    }


    void Grap()

    {

        Hook.transform.position = Vector3.MoveTowards(Hook.transform.position, GrapPos[grapNum[nowgrap]].transform.position, Speed * Time.deltaTime);

        if (Hook.transform.position == GrapPos[grapNum[nowgrap]].transform.position)

        {

            Invoke("chkPull", 1f);

        }

    }


    private void Pull()

    {

        Hook.transform.position = Vector3.MoveTowards(Hook.transform.position, new Vector3(0, 0, 0), pullSpeed * Time.deltaTime);

        wallObj[grapNum[nowgrap]].transform.position = Vector3.MoveTowards(wallObj[grapNum[nowgrap]].transform.position, StopPos[grapNum[nowgrap]].transform.position, pullSpeed * Time.deltaTime);

    }


    void chkPull()

    {

        grapChk = false;

    }


    void CreateUnDuplicateRandom(int min, int max)

    {

        int currentNumber = Random.Range(min, max);


        for (int i = 0; i < max;)

        {

            if (grapNum.Contains(currentNumber))

            {

                currentNumber = Random.Range(min, max);

            }

            else

            {

                grapNum.Add(currentNumber);

                i++;

            }

        }

    }


    public void CutLine()

    {

        if (!cutChk)

        {

            cutChk = true;

            Hook.SetActive(false);

            Hook.transform.position = Boss.transform.position;

            nowgrap += 1;

            if (nowgrap < 4)

                Invoke("NextGrap", ws);

            else

                Invoke("EndPattern", ends);

        }

    }


    void NextGrap()

    {

        lineCol.GetComponent<ShotCollisionDamageLine>().CurHP = lineCol.GetComponent<ShotCollisionDamageLine>().MaxHP;

        Hook.SetActive(true);

        lineCol.SetActive(true);

        grapChk = true;

        cutChk = false;

    }

    void EndPattern()

    {

        for (int i = 0; i < 4; i++)

        {

            wallObj[i].transform.position = OriPos[i].transform.position;

        }

        Hook.SetActive(true);

        lineCol.SetActive(true);

        StopAllCoroutines();

        gameObject.SetActive(false);

    }

}