Using RayCast to do Continuous Shooting?

Hi, I currently have a RayCast that acts more of a combat rifle/pistol. It shoots once per click. How do I transform my script to make it into a machine gun script where I don’t have to click once, but instead hold the button for continuous fire?

public class Shooter : MonoBehaviour



{
    void Update ( )
    {
        // 1. Wait for a mouse click.
        if ( Input.GetButtonDown( "Fire1" ) )
        {
            Shoot( );
			
			
        }
    }

    void Shoot ( )
    {
        // 2. Create a ray that travels from your camera 
        //    in the direction it's facing.
        Ray ray = new Ray( transform.position, transform.forward );
        RaycastHit hit;
        if ( Physics.Raycast( ray, out hit ) )
        {
            // 3. Check the first thing it hits, is it your enemy?
            //    If so (actually there is nothing defined as enemy);
            hit.transform.SendMessage( "OnBullet",
                SendMessageOptions.DontRequireReceiver );
        }
    }

Use this event instead of GetButtonDown. Only this way you will fire on every update so you need to implement “RateOfFire” variable and use Time.deltaTime to slow down your shooting.

LAZINESS EDIT:

Dude, you have 14 questions without single acception. And really simple instruction here but you dont event bother. There was no “small problems” to fix. Search and replace would almost do it…

I didnt compile this:

public class Shooter : MonoBehaviour

public float timeBetweenShots = .3f;
private float timeSinceLastShot = 0;

{
    void Update ( )
    {
        // 1. Wait for a mouse click.
        timeSinceLastShot += Time.deltaTime;
        if ( Input.GetButton( "Fire1" ) && timeSinceLastShot >= timeBetweenShots)
        {
            Shoot( );


        }
    }

    void Shoot ( )
    {
        // 2. Create a ray that travels from your camera 
        //    in the direction it's facing.
        Ray ray = new Ray( transform.position, transform.forward );
        RaycastHit hit;
        if ( Physics.Raycast( ray, out hit ) )
        {
            // 3. Check the first thing it hits, is it your enemy?
            //    If so (actually there is nothing defined as enemy);
            hit.transform.SendMessage( "OnBullet",
                SendMessageOptions.DontRequireReceiver );
            timeSinceLastShot = 0;
        }
    }