My script for delay between bullet spawn and reload is not working properly

I am having a problem with the script, i am trying to shoot 5 bullets and after 5 bullets it should have a 5 sec gap before it shoots

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawn_Bullet : MonoBehaviour {
	public GameObject bullet;
	public GameObject SpawnPos;
	public int bulletcount;
	private bool isreloading;
	private float instantiatetimer;
	// Use this for initialization
	void Start () {
		isreloading = false;
		bulletcount = 6;
		instantiatetimer = 2.0f;
	}
	
	// Update is called once per frame
	void FixedUpdate () 
	{ 
		if (isreloading==false) 
		{ 
			if (Input.GetKeyDown(KeyCode.Space)) 
			{	
				if (bulletcount > 0)
				{
					Debug.Log ("bulletcount" + bulletcount);

					Instantiate (bullet, SpawnPos.transform.position, Quaternion.identity);
					--bulletcount;
				} 
				else 
				{
					isreloading = true;
					Debug.Log ("reloadstatus" + isreloading);
				}
			}
		} 
		else if(isreloading==true)
		{
			StartCoroutine (reload ());
			isreloading = false;
		}
		
	}
	IEnumerator reload()
	{
		yield return new WaitForSecondsRealtime (3);
		bulletcount = 6;
	}
}

`

hey , try this code , just some statements up and down. public GameObject bullet;
public GameObject SpawnPos;
public int bulletcount;
public bool isreloading;
private float instantiatetimer;
// Use this for initialization
void Start () {
isreloading = false;
bulletcount = 6;
instantiatetimer = 2.0f;
}

// Update is called once per frame
void FixedUpdate () 
{ 
	if (isreloading==false) 
	{ 
		if (Input.GetKeyDown(KeyCode.Space)) 
		{    
			if (bulletcount > 0)
			{
				Debug.Log ("bulletcount" + bulletcount);

				Instantiate (bullet, SpawnPos.transform.position, Quaternion.identity);
				--bulletcount;
			} 
			else 
			{
				isreloading = true;
				Debug.Log ("reloadstatus" + isreloading);
				StartCoroutine (reload ());
			}
		}
	} 

}
IEnumerator reload()
{
	yield return new WaitForSecondsRealtime (5f);
	bulletcount = 6;
	isreloading = false;
	StopCoroutine ("reload");
}

NOTE: donot instantiate so much objects in your scene,
instead of this you can use either pooling or destroy previous bullets if you are instatiating.
Thank you :slight_smile: