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 /
avatar image
0
Question by Laguna_Seca · Jul 14, 2018 at 03:47 PM · gameobjecttransformgamewords

Problem with the algorithm when deleting an object

I have a words game. The game has the function of removing an extra letter. I keep the letters in an empty game object.

         if (randomCharsString.Length > 0)
         {
             // We stand in front of the letter that we will delete
             int l = randomCharsString.Length - 1;
             // find the object of the letter in lettersGrid
             GameObject g = lettersGrid.transform.Find(randomCharsString[l].ToString()).gameObject;
             // remove a letter from a string
             randomCharsString = randomCharsString.Remove(l, 1);
 
             // get the position of a letter in the grid before deleting it
             int gOldSabling = g.transform.GetSiblingIndex();
             // remove a letter from lettersGrid
             Destroy(g);
 
             if (g == null)
             {
                 print("deleted");
             }
                 // for the place of a letter in the spilled empty cell
             inputImage = Instantiate(transparentСellPref, lettersGrid);
             inputImage.transform.SetSiblingIndex(gOldSabling);
             inputImage.gameObject.name = "transparentСell";
 
 
             // the current state of the letters in lettersGrid 
             savedLettersGridCharsString = "";
             foreach (Transform letter in lettersGrid)
             {
                 if (letter.tag != "transparentСell")
                 {
                     savedLettersGridCharsString = savedLettersGridCharsString + letter.tag;
                 }
                     
             }
 
             PlayerPrefsDB.LettersGridCharsString = savedLettersGridCharsString;
             PlayerPrefsDB.RandomCharsString = randomCharsString;
             print(savedLettersGridCharsString);
             App.money -= 1;
             PlayerPrefsDB.Money = App.money;
             moneyText.text = "" + App.money;




The fact is that the algorithm removes the letter-object and then writes down everything remaining in the string. This is necessary to play the state in case the player left the game and entered later. But the problem is that the number of letters in the line does not match the number of game objects. There is still one extra letter in the line. My brain is already boiling.

Comment
Add comment · Show 1
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 josiahsrc · Jul 14, 2018 at 04:14 PM 0
Share

Hmm... This isn't a complete answer, so I'm just commenting. In this case, I think it would be much easier to not directly tie each gameObject to a letter. Have you considered abstracting your letter data within a class? I'm not sure I completely understand what you're trying to accomplish, but I think an abstraction of it would look something like this (this isn't tested):

 public class LetterTileGrid
 {
     LetterTile[,] m_LetterTiles;
     int m_Rows = -1;
     int m_Columns = -1;
 
     public LetterTile[,] letterTiles { get { return m_LetterTiles; } }
     public int rows { get { return m_Rows; } }
     public int columns { get { return m_Columns; } }
 
     public LetterTileGrid(int rows, int columns)
     {
         m_LetterTiles = new LetterTile[rows, columns];
         m_Rows = rows;
         m_Columns = columns;
     }
 
     // Get a string represenation of the grid
     override public string ToString()
     {
         string gridRepresentation = "Letter Tile Grid:\n";
         for (int i = 0; i < m_Rows; ++i)
         {
             for (int j = 0; j < m_Columns; ++j)
                 gridRepresentation += m_LetterTiles[i, j].letter + ", ";
             gridRepresentation += "\n";
         }
         return gridRepresentation;
     }
 
     public struct LetterTile
     {
         public bool isRemoved;
         public char letter;
     }
 }

0 Replies

· Add your reply
  • Sort: 

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

173 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 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

Render Extremely Far off Objects 1 Answer

How to mark the vertices on a mesh and make the markers follow them as you apply transformations 0 Answers

Animation issue (OnTriggerEnter) ***SOLVED*** 1 Answer

Character moving weirdly 1 Answer

2D C# destroy a GameObject on collision 2 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