Hi all i just made a shooting script and it works perfectly but the problem is the shooting is to fast i want a delay in there so if i press F on the keyboard rapidly it wont let me shoot until the delay time is over. I want to set the delay time as 1.5 sec and then the you can shoot again. After 1.5 sec you can shoot
when you press F on the keyboard
Here is my script:
var Range : float;
var Force : float = 1000;
var Clips : float = 100;
var BulletsPerClip : float = 1;
var ReloadTime: float = 0.6;
var BulletsLeft : float = 0;
var Delay : float = 2;
var fireRate = 0.05;
public var ShootSound : AudioClip;
public var ReloadSound : AudioClip;
function Update () {
if(Input.GetKeyDown(KeyCode.F) && BulletsLeft ){
PlayShootSound();
ShootRay();
}
}
function Start(){
BulletsLeft = BulletsPerClip;
}
function ShootRay(){
GameObject.Find("m1911pistoleReloadandShooting").animation.Play("Shoot") ;
var hit: RaycastHit;
var direction = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, direction * Range, Color.yellow);
if(Physics.Raycast( transform.position, direction, hit, Range)){
if(hit.rigidbody){
hit.rigidbody.AddForceAtPosition( Force * direction , hit.point);
}
}
BulletsLeft--;
if( BulletsLeft < 0){
BulletsLeft = 0;
}
if( BulletsLeft == 0){
Reload();
}
}
function Reload (){
PlayReloadSound();
GameObject.Find("m1911pistoleReloadandShooting").animation.Play("Reload") ;
yield WaitForSeconds( ReloadTime);
if( Clips >0){
Clips -=1;
BulletsLeft = BulletsPerClip;
}
}
function PlayShootSound()
{
audio.PlayOneShot(ShootSound);
}
function PlayReloadSound()
{
audio.PlayOneShot(ReloadSound);
}
Please someone help me thank you so much MCHALO