Question by
PaulDabest · Jun 28, 2016 at 10:49 AM ·
shootinggunautomaticfirst person shootergunfire
How to make an automatic fire mode for a gun (Javascript)
Hello guys, im new in unity so i want to ask this question... I have a script taken from a Youtube Tutorial. It is a single fire only script but i want to have an automatic gun. Also it would be amazing if there was a "variable" where i can change the delay between each shot, so i can use it to more weapons.
Thanks :) Please don't flame, im really new in unity! Here is the code for the other statistics of the gun (Damage, AllowedRange)
amageAmount : int = 32;
var TargetDistance : float;
var AllowedRange : float = 100;
function Update () {
if(Input.GetButtonDown("Fire1")) {
var Shot : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Shot)) {
TargetDistance = Shot.distance;
if (TargetDistance < AllowedRange) {
Shot.transform.SendMessage("DeductPoints", DamageAmount);
}
}
}
}
And here is a script which i use to play animations and sounds! (Fire1 = LeftMouseButton)
function Update () {
if(Input.GetButtonDown("Fire1")) {
var gunsound : AudioSource = GetComponent.<AudioSource>();
gunsound.Play();
GetComponent.<Animation>().Play("GunFireAK");
GlobalAmmo.LoadedAmmo -= 1;
}
}
Comment