• 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 golddevrush · Dec 27, 2014 at 07:55 PM · idle

match3 reorganize rematching

i am making game like candy-crush etc style. i got success in making it to swap,to match3, to reorganize but fail in rematch3. the game will go idle (hung / crash, don't know). anyone can help?

in rematch3, i use class to contain array of same type item that pose near to each other. then i use array that contain that class to hold all item. the class itself is wrote in a script below another class. this is the class :

     public class PoolGroup{
         public string[] baris_membername;
         public string[] kolom_membername;
         public string StartBlockName;
     
         public PoolGroup(string s) {
             StartBlockName = s;
             baris_membername = new string[0];
             kolom_membername = new string[0];
             SearchSameMember();
         }
     
         public void AddMember(string s,bool barisataukolom) {
             if (barisataukolom)
             {
                 //kalau baris
                 System.Array.Resize<string>(ref baris_membername, baris_membername.Length + 1);
                 baris_membername[baris_membername.Length
 - 1] = s;
             }
             else { 
                 //kalau kolom
                 System.Array.Resize<string>(ref kolom_membername, kolom_membername.Length + 1);
                 kolom_membername[kolom_membername.Length
 - 1] = s;
             }
         }
     
         public bool IfMatch3(){
             if (baris_membername.Length >=2) {return true;} else if (kolom_membername.Length >= 2) {return true;} else {return false;}
         }
     
         public bool IfExistMemberName(string s) {
             if (StartBlockName==s){return true;} 
             if (baris_membername.Length>=1){
                 for (int i=0;i<=(baris_membername.Length-1);i++) {if (baris_membername[i]==s) {return true;}}
             } 
             if (kolom_membername.Length>=1) {
                 for(int i=0;i<=(kolom_membername.Length-1);i++) {if(kolom_membername[i]==s){return true;}}
             }
             return false;
         }
     
         public void SearchSameMember() {
             int endbaris=GlobalVarScript.GetBoardSize-1;
             int endkolom=GlobalVarScript.GetBoardSize-1;
             int baris = GameObject.Find(StartBlockName).GetComponentInChildren<BlocksUnitScript>().myPosisiX;
             int kolom = GameObject.Find(StartBlockName).GetComponentInChildren<BlocksUnitScript>().myPosisiY;
             int jenisimage = GameObject.Find(StartBlockName).GetComponentInChildren<BlocksUnitScript>().jenisunit;
     
             //check to the right
             int i = kolom + 1;
             while (i <= endkolom)
             {
                 GameObject gameobj = GameObject.Find("blocks[" + baris + "," + i + "]");
                 if (gameobj != null)
                 {
                     if (gameobj.GetComponentInChildren<BlocksUnitScript>().jenisunit
 == jenisimage)
                     {
                         AddMember(gameobj.name,false);
                     }
                     else
                     {
                         i = endkolom;
                     }
                 }
                 i++;
             }
             //check to the left
             i = kolom - 1;
             while (i >= 0)
             {
                 GameObject gameobj = GameObject.Find("blocks[" + baris + "," + i + "]");
                 if (gameobj != null)
                 {
                     if (gameobj.GetComponentInChildren<BlocksUnitScript>().jenisunit
 == jenisimage)
                     {
                         AddMember(gameobj.name, false);
                     }
                     else
                     {
                         i = 0;
                     }
                 }
                 i--;
             }
             //check to the top
             i = baris - 1;
             while (i >= 0)
             {
                 GameObject gameobj = GameObject.Find("blocks[" + i + "," + kolom + "]");
                 if (gameobj != null)
                 {
                     if (gameobj.GetComponentInChildren<BlocksUnitScript>().jenisunit
 == jenisimage)
                     {
                         AddMember(gameobj.name,true);
                     }
                     else
                     {
                         i = 0;
                     }
                 }
                 i--;
             }
             //check to the bottom
             i = baris + 1;
             while (i <= endbaris)
             {
                 GameObject gameobj = GameObject.Find("blocks[" + i + "," + kolom + "]");
                 if (gameobj != null)
                 {
                     if (gameobj.GetComponentInChildren<BlocksUnitScript>().jenisunit
 == jenisimage)
                     {
                         AddMember(gameobj.name,true);
                     }
                     else
                     {
                         i = endbaris;
                     }
                 }
                 i++;
             }
     
         }
     
         public void ProcessMemberMatch() {
             GlobalVarScript.SetNullToBlock(StartBlockName);
             int nilai_unit = GameObject.Find(StartBlockName).GetComponentInChildren<BlocksUnitScript>().nilai;
             int countitem=1;
             int i=0;
             if (baris_membername.Length >=1) {
                 for (i = 0; i <= (baris_membername.Length - 1); i++) {
                     GlobalVarScript.SetNullToBlock(baris_membername[i]);
                     GlobalVarScript.DisplayPts(++countitem, nilai_unit, baris_membername[i]);
                 }
             }
             if (kolom_membername.Length >= 1)
             {
                 for (i = 0; i <= (kolom_membername.Length - 1); i++)
                 {
                     GlobalVarScript.SetNullToBlock(kolom_membername[i]);
                     GlobalVarScript.DisplayPts(++countitem, nilai_unit, kolom_membername[i]);
                 }
             }
         }
     
     }

then this is the method in another class (in same script) that do rematch3 :

     public static void CheckMatchAll(){
         int endPosKolom = GlobalVarScript.GetBoardSize - 1, endPosBaris = GlobalVarScript.GetBoardSize - 1;
         PoolGroup[] mPoolGroup = new PoolGroup[0];
 
         for (int i = 0; i <= endPosBaris; i++) {
             for (int j = 0; j <= endPosKolom; j++) {
                 GameObject gameobj = GameObject.Find("blocks[" + i + "," + j + "]");
                 if (mPoolGroup.Length < 1)
                 {
                     System.Array.Resize<PoolGroup>(ref mPoolGroup, mPoolGroup.Length + 1);
                     mPoolGroup[mPoolGroup.Length - 1] = new PoolGroup(gameobj.name);
                 }
                 else {
                     int k = 0;
                     bool ketemu = false;
                     while (k <= mPoolGroup.Length - 1) {
                         if (mPoolGroup[k].IfExistMemberName(gameobj.name)) { ketemu = true; }
                         k++;
                     }
                     if (!ketemu) {
                         System.Array.Resize<PoolGroup>(ref mPoolGroup, mPoolGroup.Length + 1);
                         mPoolGroup[mPoolGroup.Length - 1] = new PoolGroup(gameobj.name);
                     }
                 }
             }
         }
         bool adaMatch3 = false;
         if (mPoolGroup.Length >= 1) {
             for (int i = 0; i <= (mPoolGroup.Length - 1); i++) {
                 if (mPoolGroup[i].IfMatch3()) { 
                     mPoolGroup[i].ProcessMemberMatch();
                     if (!adaMatch3) { adaMatch3 = true; }
                 }
             }
         }
         if (adaMatch3) {GlobalVarScript.ReOrganize();}
 }




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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by golddevrush · Jan 03, 2015 at 05:58 PM

i found the answer myself. according to my test and my logic, it happen because the update of frame. when i change using class to a struct and using a script that control in-game status every update. it response as i want (though it lack of animation hehe).

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How can i solve the following problem? The left-hand side of an assignment must be a variable, a property or an indexer. 2 Answers

How to animate more platforms without using new animation for every single one? 0 Answers

Unity 2D - How do you get a sprite to react to gravity? 0 Answers

How to properly set the gui texture2d for android? 1 Answer

Updating a collision inside function update? 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