How Do I Make My Gun JUST Semi-AutoMatic?

I Have a script set up here.

var projectile : Rigidbody;
var speed = 5;

function Update () {

if ( Input.GetButton ("Fire1")) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));

Destroy (clone.gameObject, 4);


}}

But How Do I make it semi auto? any help please?

Change the Input.GetButton to Input.GetButtonDown
It only checks for when the button gets pressed. Hope that helps :slight_smile:

This should work for you:

private var shooting = false;
var shotSpacer = 0.1; //time between shots in burst
var burstSpacer = 0.5; //how long after a firing burst you must wait to fire another
var burstShots = 3; //number of shots in a burst
private var remainingShots : int;
var projectile : Rigidbody; //your bullet object
var speed = 5;

function Update () {
	if(Input.GetButtonDown("Fire1") && !shooting){
		BurstFire ();
	}
}

function BurstFire () {
	shooting = true;
	remainingShots = burstShots;
	InvokeRepeating("Fire", 0, shotSpacer);
	yield WaitForSeconds(burstSpacer);
	shooting = false;
}

function Fire () {
	if(remainingShots > 0){
		clone = Instantiate(projectile, transform.position, transform.rotation);
		clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
		remainingShots --;
	}else{
		CancelInvoke();
	}
}

by default it will fire a burst of 3 bullets but you can change the variables to suit your needs.

Scribe

canShoot : float = false;

coolDown : float = 0;

coolDownMax : float = 2;
    
function Update(){
    
if(coolDown < coolDownMax){
       coolDown += Time.deltaTime;
       canShoot = false;
    }
    
if(coolDown >= coolDownMax){
       canShoot = true;
    }
    
if ( Input.GetButton ("Fire1")) {
    
    clone = Instantiate(projectile, transform.position, transform.rotation);
    clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
    canShoot = false;
    coolDown = 0;
     Destroy (clone.gameObject, 4);
     
    }
    
    }

This is untested code but I think it will work. Tell me if there are any errors. Also, the time between each shot is 2 seconds. You can change this by changing the coolDownMax variable. Tell me if you need anything else :slight_smile: