I’m working on a script for guns in my game, and i’d like to customize the rate of fire. This script is for automatic weapons. How would i go about doing this?
var Bullet : Transform;
var Spawn : Transform;
var shellSpawn : Transform;
var shell : Transform;
var muzzleflash : Transform;
var BulletForce = 4000 ;
var shellForce = 100 ;
var Sounds:AudioClip[];
var RateOfFire = 0 ;
function Update ()
{
if(Input.GetButton("Fire1"))
{
Shot();
}
}
function Shot()
{
var pel = Instantiate(Bullet, Spawn.position, Spawn.rotation);
pel.rigidbody.AddForce(Spawn.forward * BulletForce);
var sel = Instantiate(shell, shellSpawn.position, shellSpawn.rotation);
sel.rigidbody.AddForce(shellSpawn.forward * shellForce);
Instantiate(muzzleflash, Spawn.position, Spawn.rotation);
audio.clip = Sounds[Random.Range(0, Sounds.length)];
audio.Play();
}