- Home /
Why aren't all my barrels firing at the same time?
Right now I have two barrels on my ship. I want both barrels to fire at the same time.
The first thing I do is find the Gun.cs
in my PlayerController.cs
:
void Start()
{
gun = transform.GetComponent<Gun>();
}
In the Gun.cs
I find all the barrels recursively. Then if the player is shooting through the PlayerController.cs
I fire the gun's barrels:
public void FireProjectile()
{
if (currentFireTime < 0.0f)
{
foreach (var barrel in barrels)
{
{
GameObject bullet = objectToShootPool.getPooledObject();
if (bullet)
{
bullet.transform.position = barrel.transform.position;
bullet.transform.rotation = barrel.transform.rotation;
bullet.SetActive(true);
}
}
currentFireTime = fireRatePerSecond;
}
}
}
I don't know where the problem is but the fire in a staggered pattern.
Here is a picture:
Answer by ScaniX · Dec 22, 2017 at 11:04 AM
Did you check the position of your barrel transforms in this rotation? Probably the parent has a weird nonconform scale and their position is off.
@ScaniX you are right. I just thought it was all because of my code. Why don't you add that as the answer and I"ll give you the credit?
Your answer
![](https://koobas.hobune.stream/wayback/20220612145025im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
InvokeRepeating() not working. 1 Answer
Adding Rotation & Fire Rate to an Object Pool 0 Answers
Shooting with Limited Ammo 2 Answers
Need hep with pooling(call Cs in Js) 0 Answers