[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");
}
κ²μμ κ³κ°€λ‘