I have a script which covers most of my weapons shooting and reloading, but I have this problem when you press r you dont have to wait for the reload animation to finish instead you can press r and start shooting straight away. How would I alter this script so that you have to wait a few seconds before you can start shooting again?
this is the script,
var amountOfShots = 8;
function Update (){
if(Input.GetButtonDown(“Fire1”)){
Shoot();
}
if(Input.GetKeyDown(“r”)){
amountOfShots = 8;
}
}
var shootSound : AudioClip;
var bloodPrefab : Transform;
var sparksPrefab : Transform;
var hit : RaycastHit;
var range = 500;
function Shoot (){
if(amountOfShots > 0){
amountOfShots--;
if(shootSound){
audio.PlayOneShot(shootSound);
}
if(Physics.Raycast(transform.position, transform.forward, hit, range)){
var rot = Quaternion.FromToRotation(Vector3.up, hit.normal);
if(hit.collider.tag == "Enemy"){
if(bloodPrefab){
Instantiate(bloodPrefab, hit.point, rot);
}
hit.collider.gameObject.SendMessage("ApplyDamage", 25, SendMessageOptions.DontRequireReceiver);
}else{
if(sparksPrefab){
Instantiate(sparksPrefab, hit.point, rot);
}
}
}
}
}