I want to know how to make my gun semi auto instead of full automatic? I’ve tried to use a boolean to turn of the inovake but it did not work. I try to make a shotgun/sniper/rifle and wonder if anyone knows how to make it?
Here’s the script:
#pragma strict
var reloadSound: AudioClip;
var fireSound: AudioClip;
var NoAmmoSound : AudioClip;
var bullet : GameObject;
var scope: GameObject;
var laser: GameObject;
var silencer: GameObject;
private var hasScope: boolean;
private var hasLaser: boolean;
private var hasSilencer: boolean;
var bulletsPerSecond = 14.0;
private var shooting = false;
var bulletForce = 1000.0;
var bulletsInMag = 30;
var magsLeft = 10;
var LoadAmmount = 30;
private var reloading = false;
var reloadCount = 0;
var otherObj : GameObject;
var MainCamera : Transform;
var style : GUIStyle;
function Start() {
hasScope = Random.value < 0.35; // scope chance: 20%
hasLaser = Random.value < 0.25; // laser chance: 35%
hasSilencer = Random.value < 0.15; // silencer chance: 25%
scope.SetActiveRecursively(hasScope);
laser.SetActiveRecursively(hasScope);
silencer.SetActiveRecursively(hasScope);
}
{
InvokeRepeating("Shoot", 0.0, 1.0 / bulletsPerSecond);
}
function Shoot() {
if (!shooting) return;
var go = Instantiate(bullet, transform.position, transform.rotation);
go.rigidbody.AddRelativeForce(Vector3.up * bulletForce);
audio.PlayOneShot(fireSound);
bulletsInMag--;
}
function Update(){
shooting = false;
Debug.Log(bulletsInMag);
if(Input.GetAxis("Fire1") && bulletsInMag > 0 && magsLeft > -1 && !reloading){
shooting = true;
}else if(bulletsInMag <= 0 && magsLeft <= 0 && Input.GetMouseButton(0)){
audio.PlayOneShot(NoAmmoSound);
}else if(bulletsInMag <= 0 && magsLeft > 0){
shooting = false;
Reload();
}
}
function Reload(){
reloading = true;
otherObj.GetComponent(Animations).enabled = false;
otherObj.animation.CrossFade ("Reload");
audio.PlayOneShot(reloadSound);
bulletsInMag = LoadAmmount;
magsLeft -= 1;
yield WaitForSeconds(2);
reloading = false;
otherObj.GetComponent(Animations).enabled = true;
}
function OnGUI(){
GUI.Box (Rect (Screen.width - 300,Screen.height-35,200,80), bulletsInMag.ToString(), style);
GUI.Label (Rect (Screen.width - 200,Screen.height-35,200,80), magsLeft.ToString(), style);
}