Machine gun fire

Hey, I’m trying to get my gun to fire as a machine gun would. I can’t see what is wrong with my code so I hope somebody here can!

public float fireRate=0.5f;
public float nextFire=0.0f;

void Update () {
if(gun.active)
{
	if(Input.GetMouseButton(0)&&Time.deltaTime>nextFire){
		Debug.Log("shot fired");
		nextFire = Time.deltaTime+fireRate;
		audio.Play();
		Ray ray=Camera.main.ScreenPointToRay(shootingPoint);
		RaycastHit hit=new RaycastHit();
		if(Physics.Raycast(ray,out hit))
		{
			if(hit.collider.gameObject.tag=="barrel")
			..........................

So that is the main code I believe is causing problems. Sometimes the gun fires as soon as it is picked up without pressing the mouse button. Perhaps Input.GetMouseButton(0)is wrong as i changed that from Input.GetMouseButtonDown(0)?

if(Input.GetMouseButton(0)&&Time.deltaTime>nextFire)
{


nextFire = Time.deltaTime+fireRate;
` …
}

change it to this:

if(Input.GetMouseButton(0)&&Time.time>nextFire)
{
 ....
 ....
 nextFire = Time.time+fireRate;

` …
}

GOOD LUCK!

Thanks! it’s repeating fire now but when I change the firerate it is still firing at the same rate no matter if i have 2.0f or 0.1f as the value!