var explosionRate : float = 0.2f;
var nextExplosion : float = 0.0f;
function Update(){
if ( Input.GetButton("Explode") Time.time > nextExplosion ){
nextExplosion = Time.time + explosionRate;
Shoot();
}
}
shooting game, with 0.2 seconds delay each shoot, by button hold
just wondering do you have a better approach to this fire rate kinda stuff
the one that less code maybe and more efficient ??
Other than the calculation of rounds per minute I can’t see anything wrong with your approach.
rate = 60 / rpm;
I do it like this:
var bullet : GameObject;
var CoolDownTimer : float = 0.0;
function Update ()
{
CoolDownTimer -= Time.deltaTime;
if(CoolDownTimer < 0.0)
{
CoolDownTimer = 0.0;
}
if(Input.GetKey("space") CoolDownTimer == 0.0)
{
var projectile: GameObject;
projectile = Instantiate(bullet, transform.position, transform.rotation);
CoolDownTimer += 0.5;
}
}
Simpler, more efficient, and more expandable IMO. For example, in my project that I’m working on right now, I’ve made a shotgun weapon(multiple projectiles at once in different directions), and a multi-barreled gun(using booleans), etc., all from this base code. With this base weapon script a lot is possible 