자꾸 이런거 물어봐서 미안행... 근데 유니티가 자꾸 멈춘다 이유를 모르겠다.
내가 만들려는거는 오브젝트를 껏다 켰다 하면서 쓰는 보스 스펠 같은건데 한번은 작동이 잘 되는데 두번째 활성화 하면 그 순간 유니티가 멈춤 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);
}
}
CreateUnDuplicateRandom 여기서 i++ 가 else 하단에 있어가지고 무한루프 가능성이 존재함
내 추측은 그래 min max 가 얼마가 들어가는지 모르겠지만 탈출 불가라면 저기밖에 안보임 나는
지금 밖이라서 나중에 확인해 볼게 고마워! - dc App
위에말대로 포문 저기서 무한도나보네. 그리고 update에 grapChk 조건체크문 뭐냐. if grapChk else하면되지 else if !grapChk 라니....
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
이거 건들다 저거 건들다 하다보니 걍 조건 추가 해야겠다 싶은곳에 쑤셔 넣었나봄.. 나중에 수정할게 고마워... - dc App