[nullreferenceexception: Object reference not set to an instance of an object ]λΌλŠ” 였λ₯˜κ°€ λœ¨λŠ”λ° 이 였λ₯˜κ°€ λœ¨λŠ” μœ„μΉ˜κ°€ A ν΄λž˜μŠ€μ— 리슀트λ₯Ό λ§Œλ“€κ³  B ν΄λž˜μŠ€μ—μ„œ κ·Έ λ¦¬μŠ€νŠΈλ¦‰ κ°–κ³  μ™€μ„œ Bν΄λž˜μŠ€μ—μ„œ λ§Œλ“€μ–΄μ§€λŠ” 였브젝트? 듀을 κ·Έ λ¦¬μŠ€νŠΈμ— μ§‘μ–΄ λ„£κ³  A ν΄λž˜μŠ€μ—μ„œ ν•΄λ‹Ή λ¦¬μŠ€νŠΈμ— λ°˜λ³΅λ¬Έμ„ λŒλ €μ„œ ν•˜λ‚˜μ”© 빼올렀고 ν•˜λŠ”λ°μš”. μ—¬κΈ° λ¦¬μŠ€νŠΈμ— μΆ”κ°€ μ‹œν‚€λŠ” λΆ€λΆ„μ—μ„œ 였λ₯˜κ°€ μžˆλ‹€κ³  λ– μš”. 어캐야 λ˜λ‚˜μš”. nullreferenceexception: 개체 μ°Έμ‘°κ°€ 개체의 μΈμŠ€ν„΄μŠ€λ‘œ μ„€μ •λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.] 라고 ꡬ글에선 λ§ν•˜λ˜λ° 어캐야 ν•˜λŠ”μ§€ 잘 λͺ¨λ₯΄κ² μ–΄μš”. γ… γ…  제발 μ•Œλ €μ£Όμ„Έμš”.

μŠ€νƒ€νŠΈμ—μ„œ [a = GetComponent(A);] 도 μ§‘μ–΄ λ„£μ—ˆλŠ”λ° 해결이 μ•ˆ λ˜μš” 어캐야 λ˜λ‚˜μš”?



public int bpm = 0;

double currentTime = 0d;


[SerializeField] Transform tfNoteAppear = null;

[SerializeField] GameObject goNote = null;



NoteL noteL;


// Start is called before the first frame update

void Start()

{

noteL = GetComponent<NoteL>();

}


// Update is called once per frame

void Update()

{

currentTime += Time.deltaTime;


if (currentTime >= 60d / bpm)

{

GameObject t_note = Instantiate(goNote, tfNoteAppear.position, Quaternion.identity);

t_note.transform.SetParent(this.transform);

noteL.boxNoteList.Add(t_note);

currentTime -= 60d / bpm;

}

}



private void OnTriggerExit2D(Collider2D collision)

{

if (collision.CompareTag("Note"))

{

noteL.boxNoteList.Remove(collision.gameObject);

Destroy(collision.gameObject);

}

}

이게 였브젝트 생성μͺ½ ν΄λž˜μŠ€μ΄κ³ μš”


public List<GameObject> boxNoteList = new List<GameObject>();


// Start is called before the first frame update

void Start()

{

}


// Update is called once per frame

void Update()

{


}


private void OnTriggerEnter2D(Collider2D collision)

{

if (Input.GetKey(KeyCode.LeftArrow))

{

Debug.Log("눌림");

for (int i=0; i<boxNoteList.Count; i++)

{

Destroy(boxNoteList[i]);

boxNoteList.RemoveAt(i);

}

}

}


이게 리슀트μͺ½ ν΄λž˜μŠ€μž…λ‹ˆλ‹€.


λ§Œλ“€κ³  싢은건 λ°©ν–₯ν‚€ 4개λ₯Ό μ΄μš©ν•œ λ¦¬λ“¬κ²Œμž„μΈλ° μœ νŠœλΈŒμ—μ„œ μΌ€μ΄λ””λ‹˜ μ˜μƒλ³΄λ©΄μ„œ ν•„μš”ν•˜λ‹€ 생각 된 λΆ€λΆ„λ§Œ μ΄μš©ν–ˆλŠ”λ° λ¨Ήν†΅μ΄λ„€μš”...γ… γ…  μ—­μ‹œ λͺ¨λ₯Όλ• κ·Έλƒ₯ 따라 λ§Œλ“€μ–΄μ•Ό λ˜λ‚˜..



public List<GameObject> boxNoteList = new List<GameObject>();


[SerializeField] Transform Center = null;

[SerializeField] RectTransform[] timingRect = null;

int count = 0;


Vector2[] timingBoxs = null;


// Start is called before the first frame update

void Start()

{

// 타이밍 λ°•μŠ€ μ„€μ •

timingBoxs = new Vector2[timingRect.Length];

for (int i = 0; i < timingRect.Length; i++)

{

timingBoxs[i].Set(Center.localPosition.x - timingRect[i].rect.width / 2, Center.localPosition.x + timingRect[i].rect.width / 2);

}



}


// Update is called once per frame

void Update()

{

}


public void CheckTiming()

{

for(int i = 0; i<boxNoteList.Count; i++)

{

float t_notePosX = boxNoteList[i].transform.localPosition.x;


for(int x = 0; x<timingBoxs.Length; x++)

{

if(timingBoxs[x].x <= t_notePosX && t_notePosX <= timingBoxs[x].y)

{

Destroy(boxNoteList[i]);

boxNoteList.RemoveAt(i);

Debug.Log("Hit" + x);

count++;

if (count == 10)

{

//SceneManager.LoadScene("Sloth");

SceneManager.UnloadSceneAsync("New Scene");

}

return;

}

}

}


Debug.Log("Miss");

}


μ œκ°€ λ³Έ μ˜μƒ 속 μ½”λ“œμž…λ‹ˆλ‹€. μ €λŠ” μ €λ ‡κ²Œ νΌνŽ™νŠΈ, 노말 타이밍 맞좜 ν•„μš” μ—†μ–΄μ„œ μ•ˆ ν–ˆλŠ”λ° μ—¬κΈ°μ—λŠ” 였λ₯˜ 해결책이 μžˆλ‚˜μš”? 이걸둜 ν–ˆμ„λ• 잘 λŒμ•„κ°€λ˜λ°..