I got this error

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;
        
    }
}

}

The answer is always the same… ALWAYS!

How to fix a NullReferenceException error

Three steps to success:

  • Identify what is null ← any other action taken before this step is WASTED TIME
  • Identify why it is null
  • Fix that

NullReference is the single most common error while programming. Fixing it is always the same.

Some notes on how to fix a NullReferenceException error in Unity3D:

http://plbm.com/?p=221

Have you assigned a GameObject to ‘enemy’ on your spawnerscript? (check that at the Inspector window)

i got it thank you