Need the script to shoot by itself

Heya guys.

Sorry to bother you with a simple question like this but I can’t seem to be able to find a simple tutorial or forum post on how to have a script shoot by itself. When i search for auto fire or something similar i get unrelated stuff.

I just want to convert this script so that it shoots by itself without any input. I still want to be able to adjust the fire rate. (It’s going to be a minigun powerup that I will activate and deactivate)

If i just delete the If statement the fire rate doesnt work anymore.

Cheers!

using UnityEngine;
using System.Collections;

public class MiniGun : MonoBehaviour {



    public GameObject shot;
    public Transform shotSpawn;
    public float fireRate;
   
   
    private float nextFire;
   
   
   
    void Update ()
    {
        if (Input.GetButton("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
            //audio.Play ();
           
           
           
        }
    }

}

No worries. I found the answer here if anyone else is curious.

Change the if input get button bla bla bla to:

if(Time.time >= nextFire)