private IEnumerator Attack() { yield return(new WaitForSeconds(0.3f)); var hasLiveCell = _grid.HasCellWithValue(ShipCellState.Alive); if (hasLiveCell) { var attackLiveCell = Random.Range(0, 100) > 20; Vector3 cell; if (attackLiveCell) { cell = _grid.GetRandomLocalCellPositionByValue(ShipCellState.Alive).AsVector3(); } else { cell = _grid.GetRandomLocalCellPositionByValue(ShipCellState.Empty).AsVector3(); } var cannonPosition = new Vector2(Random.Range(0, _grid.columns), Random.Range(0, _grid.rows)); cannon.transform.localPosition = cannonPosition; var worldPosition = cell + _grid.gridPosition.AsVector3(); cannon.FireAt(worldPosition); } this.OnTurnEnd?.Invoke(); }