I have a pretty basic burst fire function for a gun- as in shooting three times in a row. Here is the script:
void Update ()
{
timer += Time.deltaTime;
if (Input.GetButton("Fire1") && timer >= fireRate && Time.timeScale != 0)
{
if (burstFire)
{
StartCoroutine(BurstShot());
}
}
}
IEnumerator BurstShot()
{
for(int i = 0; i < burstSize; i++)
{
timer = 0f;
Quaternion bulletRot = Quaternion.Euler(90, 0, 0);
GameObject newBullet = Instantiate(bulletObj, transform.position, transform.rotation * bulletRot) as GameObject;
newBullet.GetComponent<Rigidbody>().velocity = bulletSpeed * transform.forward;
currentAmmo--;
yield return new WaitForSeconds(burstRate);
}
}
The problem is, while the first projectile will shoot forward correctly, the next two projectiles will launch upwards in a near perfect arc. And for the life of me I can’t figure out why. Why is everything in the coroutine repeating correctly except for the apparent rotation of the last two shots?