//Exchange the positions of two sweets. private void ExchangeSweets(SweetsController sweet1, SweetsController sweet2) { if (sweet1.Movable() && sweet2.Movable()) { sweets[sweet1.X, sweet1.Y] = sweet2; sweets[sweet2.X, sweet2.Y] = sweet1; if (MatchSweets(sweet1, sweet2.X, sweet2.Y) != null || MatchSweets(sweet2, sweet1.X, sweet1.Y) != null || sweet1.Type == SweetsType.RAINBOW_CANDY || sweet2.Type == SweetsType.RAINBOW_CANDY) { int tempX = sweet1.X, tempY = sweet1.Y; sweet1.MovedComponent.Move(sweet2.X, sweet2.Y, fillTime); sweet2.MovedComponent.Move(tempX, tempY, fillTime); if (sweet1.Type == SweetsType.RAINBOW_CANDY && sweet1.ColorAble() && sweet2.ColorAble()) { EliminateAnySweets clearColor = sweet1.GetComponent <EliminateAnySweets>(); if (clearColor != null) { clearColor.ClearColor = sweet2.ColoredComponent.ThisType; } EliminateSweet(sweet1.X, sweet1.Y); } if (sweet2.Type == SweetsType.RAINBOW_CANDY && sweet1.ColorAble() && sweet2.ColorAble()) { EliminateAnySweets clearColor = sweet2.GetComponent <EliminateAnySweets>(); if (clearColor != null) { clearColor.ClearColor = sweet1.ColoredComponent.ThisType; } EliminateSweet(sweet2.X, sweet2.Y); } EliminateAllMatchedSweets(); StartCoroutine(FillAll()); } else { sweets[sweet1.X, sweet1.Y] = sweet1; sweets[sweet2.X, sweet2.Y] = sweet2; } } }