Question by
Brain_Kerman · Apr 06, 2016 at 03:41 AM ·
gunreload
How to add a Gun Reload feature to my script
Im making an FPS Shooter but i cant find a way for the game to count the amount of times the gun has shot so i can put a limit before i have to reload please help
Script --->
var Projectile : Rigidbody;
var ProjectileSpeed : int = 10;
var FireRate : float = 10; // The number of bullets fired per second
var lastfired : float; // The value of Time.time at the last firing moment
function Update ()
{
if (Input.GetButton("Fire1"))
{
if (Time.time - lastfired > 1 / FireRate)
{
lastfired = Time.time;
var clone : Rigidbody;
clone = Instantiate(Projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * ProjectileSpeed);
}
}
}
Comment
Your answer
