Search Unity

Question Destroy the match objects?

Discussion in 'Scripting' started by Quast, Oct 15, 2020.

  1. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    Hi,

    I'm trying to make "Candy Crush" game. I want to know how to make the script Identify those three objects. I'm using "tags". What method could help me to do that ?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,740
    There's probably a few different approaches outlined in tutorials such as these:

    Screen Shot 2020-10-15 at 11.44.38 AM.png
     
  3. VishwasGagrani

    VishwasGagrani

    Joined:
    May 12, 2018
    Posts:
    84
    You don't need tags. You can make an array of objects. And then an array of triplet-arrays. Each triplet array will contain the matching game-objects. You need to verify this when any object is clicked.
     
  4. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    I saw them before. I wrote my own script that can give me more options on moves and fill empty sort. I need a simple method to identify those matches objects.

    Thank you for your idea. The question is how to verify? Yes, I clicked on them or moved one object to make three objects matches on a row. How to make a script Identify them?
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,740
    I don't understand your question: When your script identifies three connected dots, those are the dots to destroy. Put them in a list, play an animation and destroy them.
     
  6. VishwasGagrani

    VishwasGagrani

    Joined:
    May 12, 2018
    Posts:
    84
    You identify using the gameobject's name. Each gem-game-object's name will be unique. So let's say the game object you click, you then need to scan each array you have stored. For example the gem you clicked is gem-7 Then it will be 2nd group.

    [ [gem2,gem5,gem3],[gem4,gem7,gem9],[...],[...]]
    ----------

    And if you want to use tag. Then name each 3 pairs with a tag. gem-type-1, gem-type-2. And then go through each game object, determine it's tag ( gameObject.tag ). Now I think that using tag can be easier for you as a beginner though.