Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by White8eard · Nov 25, 2014 at 08:38 AM · c#collidertriggermatchmatching

How to Destroy items in Match 3.

hello, i am trying to create a match three game, i am stuck in process of destroying the object when it has 3 items of same tag in row or column, i have tried many methods but everything seems to fail...

The MainObject has 4 child colliders on four sides to check the other objects tag...do u hv any helpful suggestion to make it work?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Andres-Fernandez · Nov 25, 2014 at 08:48 AM 0
Share

$$anonymous$$y suggestion: forget all about physics. Given the size of a level in a match 3 game, you can keep everything inside a logical representation (you even have rows and columns). Whenever you get to a stable situation (i.e. no objects moving/falling) check each object for its neighbours, one at a time. While you are checking one object keep track of the number of matching neighbors, if more than 3 mark them as "destroy". Rince and repeat.

[edit:] You can improve this by tracking the turn and check only for the objects that have moved in the last turn.

avatar image White8eard · Nov 28, 2014 at 11:10 AM 0
Share

@andres i read your comment late, i used physics to check the neighbours, well you can say it works 90% fine and in some instances it screws up and destroys when it should, can u brief me more on how to not use physics and how to assign them positions,give gravity and check neighbours?

avatar image White8eard · Nov 30, 2014 at 09:46 AM 0
Share

@koray1396 i created the tiles, made tiles swap, using multidimensional array,but how do i make them check for match all the time?

avatar image Andres-Fernandez · Dec 02, 2014 at 03:52 PM 0
Share

I would wait for a stable moment/turn (it can be when all objects have stopped) and then assign each a logical row and column based on its transform.position.

avatar image koray1396 · Dec 02, 2014 at 04:56 PM 0
Share

If you are just checking for rows and columns, like if the below will not make any match;

000

112

123

You can check for combinations at the end of every turn as Andres suggested. Not tested but my method would be something like that, sorry if there are any errors, wrote this in a hassle.

a better way would be just to check changed rows and columns. But this would be easier if you have combos or anything...

I would also create a struct for storing tile coordinates easily.

 public struct TileCoord{
     public int Column, Row;
     public TileCoord(int x, int y){
         Column = x;
         Row = y;
     }
 }
 
 void CheckForCombinations(int colNr, int rowNr){
     //Check Columns For Combinations
     List<TileCoord> TilesToDestroy = new List<TileCoord>();
     int startRowNumber = 0;
     int numberOfTiles$$anonymous$$atched = 0;
     for(int i = 0; i < NumberOfColumns; i++){
         numberOfTiles$$anonymous$$atched = 0;
         for(int y = 0; y < NumberOfRows - 1; y++){
             if(tileTypes[i,y] != 0 && tileTypes[i,y] == tileTypes[i,y+1]){
                 numberOfTiles$$anonymous$$atched += 1;
                 if(numberOfTiles$$anonymous$$atched == 1){
                     startRowNumber = y;
                 }
             } else {
                 if(numberOfTiles$$anonymous$$atched >= 2){
                     for(int z = 0; z <= numberOfTiles$$anonymous$$atched; z++){
                         TilesToDestroy.Add(new TileCoord(i, startRowNumber + z));
                     }
                 }
                 numberOfTiles$$anonymous$$atched = 0;
             }
         }
         if(numberOfTiles$$anonymous$$atched >= 2){
             for(int z = 0; z <= numberOfTiles$$anonymous$$atched; z++){
                 TilesToDestroy.Add(new TileCoord(i, startRowNumber + z));
             }
         }
         //Check Rows Similar To Above
         //Destroy tiles in list
     }

otherwise if tiles can make a match as below;

110

122

344

Then you would need a a more complex way to check combinations, I would check neighbours of newly added tiles, and neighbours of neighbours of newly added (or changed) tiles.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by koray1396 · Nov 28, 2014 at 11:59 AM

use multidimensional array to store tile types, such as;

int[,] tileTypes = new int[NumberOfColumns, NumberOfRows]; //0 would be empty tile. 1,2,3... would represent types.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sitansh · Aug 31, 2017 at 09:01 AM 0
Share

Can you please send me the code regarding this(how to destroy gems if the colour matches) $$anonymous$$y email is sitanshyadav@gmail.com Please.........

avatar image
0

Answer by nirharpaz · Dec 02, 2014 at 05:12 PM

did you try the function Destroy(obj:Object, t:float) ?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Checking gameobject in Collider range only on method call 1 Answer

Which setup should I use for spawning? 0 Answers

Distribute terrain in zones 3 Answers

Change Scene When All balls Enter Collider 1 Answer

How can I disable this collider, when two are present on the gameobject 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges