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 /
  • Help Room /
This question was closed Feb 02, 2017 at 11:39 AM by DevMagi for the following reason:

already answered: http://answers.unity3d.com/questions/1307420/trying-to-get-gameobjects-assigned-to-arrayxy.html#answer-1307502

avatar image
0
Question by DevMagi · Jan 29, 2017 at 06:00 PM · array of gameobjectspositions

assigning gameobjects to an 2Darray

really new to Unity and I am trying to recreate a minesweeper kind of game with variable level sizes. i am getting a lot of different pieces from different tutorials and i have figured out how to dynamically create the playing field gameobjects but to do most of the game logic i need to assign these to an array.

and this is where i got stuck. i was successful at first with using the x,y location of the gameobject to assign it in the correct location of the array but now i switch to adaptive screensizes i am not sure anymore how to get the gameobjects into the array.

i had this part when the game objects had a fixed position:

 //register to grid
         int x = (int)transform.position.x;
         int y = (int)transform.position.y;
            
         Grid.elementArray[x, y] = this;

and i am hoping new logic in here when i create the grid. i am looking for any help trying to either find the position of each gameobject. or just a better solution to my problem the i am working towards. it is either really simple and i am not seeing it or i really do not understand arrays.

  public void GenerateGrid()
     {
 
         GameObject cellInputField;
         RectTransform rowParent;
         
         for (int rowIndex = 0; rowIndex < numOfRows; rowIndex++)
         {
             rowParent = (RectTransform)Instantiate(panelRow);
             rowParent.transform.SetParent(Gridset);
             rowParent.transform.localScale = Vector3.one;
             
             for (int colIndex = 0; colIndex < numOfColumns; colIndex++)
             {
                 cellInputField = (GameObject)Instantiate(cellgrid);
                 cellInputField.transform.SetParent(rowParent);
                 cellInputField.GetComponent<RectTransform>().localScale = Vector3.one;
                 
                 countTotCell += 1;
                 
                 
 
             }
             
         }
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

89 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

Related Questions

Objects positions in an Array 0 Answers

How to Move a GameObject to a fixed position 1 Answer

Problem activate/ deactivate GameObject and array 2 Answers

Best way to set game object transforms 2 Answers

Merging multiple array's from a specific class without manually targeting them 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