I’ve recently updated to Unity 5.6.x and I noticed that the bubble shooter game broke. I haven’t been able to find out what the issue with Unity is, but by changing the Edge colliders with Box colliders in the wall game objects I fixed the problem.
You can download a package with that update here.
So what if we wanted to pick the code from the last tutorial in this series and make the grid scroll endlessly down the screen? I’d need to add new rows of balls, and in order to do that I’d have to flip the grid upside down (mainly because since the beginning of this series I’ve been using a grid that starts at the bottom of the screen.)
In order to move the grid down the screen we only need to make a few adjustments to the code. Before we had a variable controlling the number of visible rows at the beginning of the game; but with a scrolling grid you don’t need that. The grid should be entirely visible now, with a fixed gap of empty rows at the bottom of the grid which will add an initial distance between visible cells and the shooters (as well as the necessary empty rows which will need to add the player’s bullets which do not create an immediate match.)
So what if you want to use multiple shooters? The class I wrote for the ray cast shooter can be easily updated so we can use as many shooters as we want in the game.
I’ll place five shooters at the bottom of the screen, and for the sake of this tutorial, each shooter will now have a fixed color type, so the color won’t change after a shot.
(Although you could easily keep the existing logic that handles that in the touch up handler, who knows, it might make things interesting to have each shooter select its color randomly and keep changing its color randomly after every shot.)
As I mentioned before, a bubble shooter game looks better with a hex grid, specially when the targets are circles. A square grid populated with circles should not run matches diagonally, because it looks weird. So with a square grid you can have a maximum of four neighbors for each cell (diagonal neighbors look too far away when using circles). But with a hex grid you can have up to six neighbors.
We need to remove all balls (bubbles) which are no longer connected to the main body of the grid.
I do this with a new method in the Grid class, called right after I remove matches from the grid.
Now that I have the path on screen, shooting the bullet is quite easy. I can use the same path to move the bullet on the screen. So after the user selects a path and releases the touch on the screen, we activate a bullet gameObject, and animated it along that path.