I have a simple turret with two barrels, each able to instantiate and shoot a projectile. But I would like them to shoot alternately, like the old WW2 anti-air guns, rather than both shooting at once. Here is the script I have applied to both barrels:
public Rigidbody bullet;
public float power = 1500f;
public float ShootTimer = 0.01f;
public float nextFire = 0.0f;
//Shooter script
if(Input.GetButton("Fire1")&& Time.time > nextFire){
nextFire = Time.time + ShootTimer;
Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
Vector3 upwards = transform.TransformDirection(Vector3.up);
instance.AddForce(upwards * power);
}
}
}
Tweaking my Shoot Timer and Next Fire variables doesn’t really give me satisfactory results. They may alternate for a few seconds but then for some reason it appears as if they both start to shoot faster. Also letting go of the fire button and pressing it again will cause them to start firing again at the same time. Am I missing some other variables?