Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jun 21, 2019 at 01:00 AM by JacboyX for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by JacboyX · Jun 17, 2019 at 11:18 PM · puzzlemechanicsmatchinggeneral programming

Puzzle Piece Match Mechanic

I need help figuring out how to make the match mechanic for each individual color. In this game you match 2 of the same color to gain points. Think of this game as puyo puyo at it's core foundation, or as in the industry we call Minimum Viable Products (MVP). I'm still having trouble with the flip mechanic for the pieces, but right now I'll focus on the match mechanic. What kind of code do I need in order to make the match 2 mechanic fully operational?

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by toddisarockstar · Jun 18, 2019 at 04:48 AM

Your code should use a 2D array to keep track of where things are. this way you can use x and y coordinates to look at squares and check things. when you check things you use a loop inside a loop to page through every coordinate. here is an example of setting up a grid of colors, setting some colors on the grid, and finally printing where the matches are:

    public Color[,] c;
     void Start () {
 
         c = new Color[10, 10];
         c [1, 2] = Color.red;
         c [8, 8] = Color.green;
         c [8, 2] = Color.blue;
         c [1, 3] = Color.red;
 
         findmatch ();
     }
     
     void findmatch(){
         int x = 10;
         while(x>1){x--;
             int y = 10;
             while(y>1){y--;
             
                     if(c[x,y]==c[x-1,y]||c[x,y]==c[x,y-1]){
                     if(c[x,y]!=new Color(0,0,0,0)){
                     print ("found match next to  "+x+","+y);}
                 }
             
             }} }

Comment
Add comment · Show 2 · 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 JacboyX · Jun 18, 2019 at 04:52 AM 0
Share

Thanks dude. By the time this is done and over with, I'm gonna make a tutorial of this on YouTube. Cause nobody has done one at all. Course there's something else. Forgive me, but here's some of the code for the grid:

     public static int gridwidth = 4;
     public static int gridheight = 12;
 
     public static Transform[,] grid = new Transform[gridwidth, gridheight];
 

Any way to attach the color code to the sprites and grid?

avatar image toddisarockstar · Jun 18, 2019 at 01:59 PM 0
Share

you just use a custom class ins$$anonymous$$d of the color variable.

     public class box {
         Sprite sprite;
         Color color;
         public box (Sprite S, Color C){
             sprite  = S; color = C;
         }
     }
 
 
     public box[,] c;
     void Start () {
 
         c = new box[10, 10];
         c [1, 2] = new box (somesprite, Color.red);
         c [8, 8] = new box (somesprite, Color.green);
 
     }

Follow this Question

Answers Answers and Comments

106 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

How do I force the player to press buttons in order? 2 Answers

Pattern Detection 1 Answer

Colour Matching Game: Search board for matches? 2 Answers

How to set different score values to different prefabs of an array? 0 Answers


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