Question by
YoloJoe · Feb 06, 2016 at 03:44 PM ·
shootinggun script
My gun is only shooting bullets every 8th shot..?
Hello. I have made a simple gun script:
var projectile : Rigidbody;
var speed = 20;
var fireRate = 0.5;
private var nextFire = 0.0;
function Update ()
{
if (Input.GetButton ("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3 (0, 0, speed));
GetComponent.<AudioSource>().Play();
GetComponent.<ParticleSystem>().Play();
Destroy (clone.gameObject, 5);
}
}
However, the gun does not fire every time I press Mouse 0. The audio plays every time but not the bullets.
Comment
Your answer
Follow this Question
Related Questions
How to make gun shoot in the crosshair & automatic fire (Javascript) 1 Answer
NullReferenceExeption on my gun 1 Answer
Enemy Shoots at opposite direction of player. 0 Answers
Shooting sideways? 1 Answer
Enemy AI for Shooting Game 1 Answer