The Object you want to instantiate is null.

I’m creating a simple game where all the player has to do is avoid red squares. It’s a 2d game and I’m still very new to unity and c# so I’m not completely sure what I’m doing. I keep running into this problem on my enemy spawn script “The Object you want to instantiate is null.”

public float maxTime = 1;
private float timer = 0;
private GameObject badGuy;
public float height = 12;
public object GameObject;
private GameObject newbadGuy;

void Start()
{
    GameObject newbadGuy = Instantiate(badGuy);
    newbadGuy.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 12);
}

void Update()
{
    if (newbadGuy != null && timer > maxTime)
    {
        GameObject newbadGuy = Instantiate(badGuy);
        newbadGuy.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 12);
        Destroy(newbadGuy, 5);
        timer = 0;
    }

        timer += Time.deltaTime;
}

This problem is making the enemy unable to spawn or destroy new enemies.

using System.Collections;
using UnityEngine;

public class MySpawner : MonoBehaviour
{

	[SerializeField] GameObject _prefab = null;
	[SerializeField] float _tick = 1f;// seconds
	[SerializeField] float _height = 12f;
	
	[Header("Read Only")]
	[SerializeField] GameObject _instance = null;

	void Start ()
	{
		StartCoroutine( nameof(SpawnRoutine) );
	}

	IEnumerator SpawnRoutine ()
	{
		var delay = new WaitForSeconds( _tick );
		while( true )
		{
			if( _instance==null )
			{
				Vector3 spawnPoint = transform.position + new Vector3( 0 , Random.Range(-_height, _height) , 12 );
				_instance = Instantiate( _prefab , spawnPoint , Quaternion.identity );
				Destroy( _instance , 5 );
			}

			yield return delay;
		}
	}

}