when i start the game it works for seconds and stop and i got this error in console
MissingReferenceException: The object of type ‘UnityEngine.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. Parameter name: data
UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at :0)
UnityEngine.Bindings.ThrowHelper.ThrowArgumentNullException (System.Object obj, System.String parameterName) (at :0)
UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) (at :0)
UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at :0)
UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at :0)
spawnerscript.Update () (at Assets/scripts/spawnerscript.cs:19)
this is the script that make the error
using UnityEngine;
public class spawnerscript : MonoBehaviour
{
public float time = 10;
public GameObject enemy;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
time -= Time.deltaTime;
if (time <1)
{
Instantiate(enemy,new Vector3 (Random.Range(5f, -5f), Random.Range(6, -6), 0) , Quaternion.identity);
time = 10;
}
}
}