Esempio n. 1
0
    public void SpawnNextRow()
    {
        var newRow = new List <GridBall>();

        gridBallsParent.DOMoveY(gridBallsParent.position.y - rowDistance, 1f).OnComplete(() =>
        {
            if (activeBalls.OrderBy(b => b.GridData.RowIndex).First().gameObject.transform.position.y < -3.5f)
            {
                EventGameOver?.Invoke();
                return;
            }

            var isEvenRow = rowSpawnIndex % 2 == 0;
            for (int i = 0; i < ballsPerRow; i++)
            {
                var gridBall = Instantiate(gridBallPrefab, isEvenRow ? evenRowSpawnTransforms[i] : oddRowSpawnTransforms[i]);
                gridBall.transform.SetParent(gridBallsParent);
                gridBall.SetInfo(GameplayManager.Instance.GameSettings.BallSettings[Random.Range(0, GameplayManager.Instance.GameSettings.BallSettings.Count)]);
                gridBall.SetGridData(rowSpawnIndex, i);
                newRow.Add(gridBall);
                activeBalls.Add(gridBall);
            }
            rowSpawnIndex++;

            foreach (var ball in lastSpawnedRow)
            {
                if (ball != null)
                {
                    ball.CollectNeighbours();
                }
            }

            foreach (var ball in newRow)
            {
                ball.CollectNeighbours();
            }

            lastSpawnedRow = newRow;

            EventNextRowSpawned?.Invoke();
        });
    }
Esempio n. 2
0
 public void GameOver()
 {
     isOver = true;
     EventGameOver?.Invoke();
 }