Objective: Making a Tile-Match Game in Unity from Scratch.
In the first step create an empty gameObject called Grid then add a Grid Layout Group.
In the second step, I will create an empty game object rename it Item_01, then add two images and one text, at the bottom of Item_01 I will add another image called _cover_Image.
Duplicate this Item_1 and rename it to Item_2, then change the Item_image to another image of your choice, and change the ItemName.I will repeat this for 3rd Item.
Enable the Item Image_Cover then create a new script called Button and attach it to All items.
Create a new script called GameManager, go to the Button Script create an int variable for score amount, GameManager, and get the GameManager in the start method in the Button Script.
Open GameManager create a text variable and public method called Update Score with int parameter, assign the text to this int, and convert this int to string.
Go to the Button script create a public method called AddScore, and then call UpdateScore by passing _scoreAmount as its parameter.
Drag all Items into the Prefab Folder, then take this Item to Grid game Object and make the constrain to Fixed Row of 3.
Create an Array of GameObject in the GameManager, and drag and drop all 3 Items in the inspector. then delete those in the Hierarchy.
Create a GameObject and serialize it, call it grid then use for loop to Instantiated 15 times in those Items array in a random way. Then Create two texts for the score title and score amount and position them on the left.
Select the GameManager and drag and drop the score Amount text and Grid game object to the inspector.
Select the Item and add the score amount for the bomb, I will add negative number for this one.
Note: I have disabled the cover image to know which item needs to have a negative or positive.
Select the CoverImage and add the button Component on all 3 items.
Select those Cover Image add Event to them then drag and drop the Items each at a time to the gameObject field of the event and call the AddScore method.
Now go to the start method, We need to make sure those items are children of Grid, we need to create a gameObject handle for the Instantiated object and set its parent as Grid transform.
Select the grid and make sure the grid box is starting from the left to avoid overlapping our score text.
Create an serialzie Image variable for coverImage and disable it in the UpdateScore in the GameManage script. Then drag this image to the inspector, do this for each item. Delete those items in the hierarchy
Create a variable called score in the GameManager script, then go to UpdateScore ,increment this score with score amount and pass score as the parameter of UpdateScore.
This is how I create a tile-matching game from scratch. you can expand this game as you want.
See you in the next one.