๊ทธ๋ฅ ์์ฑ๋ง ํด์ฃผ๊ณ ๋์ด์ ๊ด์ฌํ๋๊ฒ์๋๋ฐ ์์ ๋ฐ ์๋ฌ๊ฐ ๋ฐ๊น?
using System.Collections; using System.Collections.Generic; using UnityEngine; public class note : MonoBehaviour { public int bpm = 0; double currenttime = 0d; [SerializeField] Transform noteappear = null; [SerializeField] GameObject gonote = null; // Update is called once per frame void Update() { currenttime += Time.deltaTime; if (currenttime >= 60d / bpm) { GameObject t_note = Instantiate(gonote, noteappear.position, Quaternion.identity); t_note.transform.SetParent(this.transform); currenttime -= 60d / bpm; } } private void OnTriggerExit2D(Collider2D collision) { if(collision.CompareTag("note")) { Destroy(collision.gameObject); } } }
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) <0x1b90fa21570 + 0x00062> in :0 UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/Scripting/UnityEngineObject.bindings.cs:202) UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/Scripting/UnityEngineObject.bindings.cs:276) note.Update () (at Assets/note.cs:22)
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
์์ฑ๋์๋ง์๋ ์๋๊ณ ๋ช์ด์๋ค๊ฐ ์ถฉ๋ํ๋ฉด ๋ ธํธํ๊ทธ๋ฌ๋ ค์๋์ ๊ฐ ์์ด์ง๋ํ์์
์๊ฐ ์ด์ธ๊ฐ ๊ทธ๊ฒ ์ด๋ ํ ์ฌ๋ถ์๊ด์์ด ์ฆ๊ฐํ๊ณ ํด๋น ์ซ์์ ๋๋ฌํ๋ฉด ์ค์ด๋๊ฒ ํ๋ ๊ฑฐ ๋ก์ง์ด ์๋ก ์ถฉ๋๋์ง ์๋?
๋์ด์ ์ฆ๊ฐํ์ง๋ง๋ผ๊ณ boolean ๊ฐ ์ฃผ๋ ๊ฑฐ ํ๋ฒ ์๋ํด๋ด
์ค..๋๊ธด๋๋ค ๊ณ ๋ง์