Hi there,
i have a spaceship with several turrets that i manage with an array. I had it like go through the array and fire (bool colled fired set to true after shot), the wait for some time (coroutine that sets the bool to false again so turrets can fire again). That makes my turrets fire simultaniously. now i want a second fire mode where the turrets fire one after another with that delay.
I tried different approaches but i wont get it right somehow.
void ControlTurrets()
{
if (Input.GetKeyDown(KeyCode.F))
{
if (openFire)
{
LockedUI.content = "Locked on target";
openFire = false;
}
else
{
openFire = true;
}
OpenFireUI.openFire = openFire;
}
for (int i = 0; i < turrets.Length; i++)
{
if (turrets *!= null)*
{
Turret _turret = turrets*.GetComponent();*
if (Cursor.visible)
{
targetController.SelectTarget(_turret);
}
GameObject _target = _turret.Target;
if (_turret.Active)
{
if (BurstUI.burst.isOn)
{
_turret.FireRate = fireRateBurst;
}
else
{
_turret.FireRate = fireRateNormal;
}
_turret.MaxSpread = _turret.FireRate / 2;
if (_target != null)
{
Turn(_turret, _target);
Pitch(_turret, _target);
if (!health.Destroyed)
{
if (openFire)
{
if (!_turret.Fired)
{
if (Locked(_turret.TurretHead))
{
if (InRange(_turret))
{
if (!HitSelf(_turret))
{
if (energy.DrawEnergy(_turret.EnergyConsumed))
{
Shoot(_turret);
_turret.Fired = true;
StartCoroutine(Wait(_turret));
}
}
}
}
}
}
}
}
}
}
else
{
Debug.LogError(“No turret referenced.”);
}
}
}
Thats the way I have it right now…firing simultanious. The Function is called inside the Update function.
Does anyone have a simple example on how to do it?