private void ClearDots() { int dotsCountBeforeClearing = CountDots(); List <List <DotScript> > dotsToClear = new List <List <DotScript> >(); //Rows HashSet <DotScript> rowsSet = new HashSet <DotScript>(); for (int j = 0; j < columns; j++) { for (int i = 0; i < rows; i++) { List <DotScript> dots = new List <DotScript>(); var dot = GetDotAtXY(j, i); if (dot && dot.color != DotScript.Type.Empty && !rowsSet.Contains(dot)) { while (true) { dots.Add(dot); rowsSet.Add(dot); if (dot.leftConnectedTo) { dot = dot.leftConnectedTo; } else { if (dots.Count > 1) { dotsToClear.Add(dots); } break; } } } } } //Columns HashSet <DotScript> columnsSet = new HashSet <DotScript>(); for (int j = 0; j < columns; j++) { for (int i = 0; i < rows; i++) { List <DotScript> dots = new List <DotScript>(); var dot = GetDotAtXY(j, i); if (dot && dot.color != DotScript.Type.Empty && !columnsSet.Contains(dot)) { while (true) { dots.Add(dot); columnsSet.Add(dot); if (dot.upConnectedTo) { dot = dot.upConnectedTo; } else { if (dots.Count > 1) { dotsToClear.Add(dots); } break; } } } } } foreach (var l in dotsToClear) { Color listColor = Color.black; int listCount = l.Count; foreach (var dot in l) { listColor = DotScript.GetColorFromType(dot.color); var ps = dot.GetComponentInChildren <ParticleSystem>(); var col = ps.colorOverLifetime; var grad = new Gradient(); grad.SetKeys( new GradientColorKey[] { new GradientColorKey(listColor, 0.0f), new GradientColorKey(Color.white, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(0.0f, 0.0f), new GradientAlphaKey(1.0f, 0.5f), new GradientAlphaKey(0.0f, 1.0f) } ); col.color = new ParticleSystem.MinMaxGradient(grad); dot.GetComponentInChildren <ParticleSystem>().Play(); dot.SetType(DotScript.Type.Empty); dot.highlight.gameObject.SetActive(false); } int score = gameplayScript.GetScoreForCombo(listCount); EventManager.OnIncreaseScore(score); EventManager.OnClearLine(l, listColor, score); } int dotsCountAfterClearning = CountDots(); int dotsClearedCount = Mathf.Abs(dotsCountAfterClearning - dotsCountBeforeClearing); EventManager.OnClearDots(dotsClearedCount); }