Here are some example projects which are available from the Unity asset store:
1. How to make the grids/cells that will contain the Candies
There are many ways in which you could achieve this. One way would be to create a “Candy Map” game object with a custom MonoBehaviour
which maintains an array of candies.
public CandyMap : MonoBehaviour {
// 2D array representing candies.
private CandyBehaviour[,] map = new CandyBehaviour[10,10];
//...
}
2. How to give a hint to the user to make a swipe that will successfully get three or more candies in a row
Write a function which searches through the grid for the first valid move. Then provide some sort of animation on the affected candies.
//...
// List of candy behaviours for hint move.
private Vector<Candy> hintMove = new Vector<Candy>();
public const int MinimumChainLength = 3;
public bool ShowHint() {
if (!FindHint()) {
// No possible moves were found!
ShuffleCandies();
return;
}
// Show particles, or otherwise animate candies:
foreach (var candy in hintMove) {
candy.FlashHint();
}
}
// Function which searches for match of at least `MinimumChainLength`.
public bool FindHint() {
int rowCount = map.GetLength(0);
int columnCount = map.GetLength(1);
// Search rows.
for (int row = 0; row < rowCount; ++row) {
// Search for chain.
for (int chainStart = 0; chainStart < columnCount - searchChainSize; ++chainStart) {
// Add initial cell in chain.
hintMove.Clear();
hintMove.Add(map[row, chainStart]);
for (int nextInChain = chainStart + 1; nextInChain < columnCount; ++nextInChain) {
if (map[row, nextInChain].Color == hintMove[0].Color)
hintMove.Add(map[row, nextInChain]);
else
break;
}
// Was a chain found?
if (hintMove.Count >= MinimumChainLength)
return true;
}
}
// Search columns.
for (int column = 0; column < columnCount; ++column) {
// Search for chain.
for (int chainStart = 0; chainStart < rowCount - searchChainSize; ++chainStart) {
// Add initial cell in chain.
hintMove.Clear();
hintMove.Add(map[chainStart, column]);
for (int nextInChain = chainStart + 1; nextInChain < rowCount; ++nextInChain) {
if (map[nextInChain, column].Color == hintMove[0].Color)
hintMove.Add(map[nextInChain, column]);
else
break;
}
// Was a chain found?
if (hintMove.Count >= MinimumChainLength)
return true;
}
}
// No chain was found, so clear hint.
hintMove.Clear();
return false;
}
3. How to make entry of the new Candies in cells
//...
public void RandomInit(int rowCount, int columnCount) {
map = new Candy[rowCount, columnCount];
for (int row = 0; row < rowCount; ++row)
for (int column = 0; column < columnCount; ++column) {
// Fill square with random candy.
var candy = CandyPool.SpawnRandom();
map[row, column] = candy;
// Position candy within grid (assumes size of 1x1 unit).
candy.transform.localPosition = new Vector3(column, row, 0f);
}
}
The above examples are very simple, but will hopefully provide some idea as to how such a game could be created.