using UnityEngine; public class CannonBattery : MonoBehaviour { public Cannon[] cannons; private int nextIndex = 0; public void FireAtTransform(Transform targetTransform, System.Action onImpact) { for (int i = 0; i < cannons.Length; i++) { int index = (nextIndex + i) % cannons.Length; if (cannons[index].IsReady) { cannons[index].ShootAtTransform(targetTransform, onImpact); nextIndex = (index + 1) % cannons.Length; break; } } } public void FireShot(GamePole targetPole, int x, int y, System.Action onShotComplete) { Transform targetTransform = targetPole.GetCell(x, y).transform; FireAtTransform(targetTransform, () => { bool wasHit = targetPole.Shot(x, y); bool wasShipDestroyed = false; if (wasHit) { var cell = targetPole.Pole[x, y].GetComponent(); var ship = cell?.deck?.GetComponentInParent(); if (ship != null && ship.IsDestroyed()) wasShipDestroyed = true; } onShotComplete?.Invoke(wasHit, wasShipDestroyed); }); } // ========================= // СБРОС ВСЕХ ПУШЕК // ========================= /// /// Принудительно снимает состояние перезарядки у всех пушек и возвращает позу в дефолт. /// instant=true — моментально вернуть геометрию/эффекты; false — дать корутинам завершиться плавно. /// public void ResetAllCannons(bool instant = true) { if (cannons == null) return; foreach (var c in cannons) { if (c == null) continue; c.ForceReloadReset(instant); } // по желанию: обнулим индекс, чтобы порядок стрельбы начинался с первой nextIndex = 0; } [ContextMenu("Reset All Cannons (instant)")] private void _ctxResetAllInstant() => ResetAllCannons(true); [ContextMenu("Reset All Cannons (smooth)")] private void _ctxResetAllSmooth() => ResetAllCannons(false); }