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 /
avatar image
0
Question by PijusVose · Jul 12, 2017 at 03:34 PM · gameobjecttilemap

GameObjects have different positions, but stay in one place

Why do all of my fields are in the same position in the Scene view, but the transform.position is different?

 private void GenerateTileMap() {
         fields = new GameObject[worldSize, worldSize];
         for (int x = 0; x < worldSize; x++) {
             for (int y = 0; y < worldSize; y++) {
                 fields [x, y] = new GameObject ("Field");
                 fields [x, y].transform.localPosition = new Vector3 (x * fieldSize, 0f, y * fieldSize);
                 fields [x, y].transform.SetParent (transform);
 
                 GameObject newField = BuildTile (10f, "Tile");
                 newField.transform.SetParent (fields[x, y].transform);
                 newField.transform.position = new Vector3 (0f, 0f, 0f);
             }
         }
     }
 
     private GameObject BuildTile(float size, string name) {
         GameObject newTile = GameObject.CreatePrimitive (PrimitiveType.Cube);
         newTile.name = name;
         newTile.transform.localScale = new Vector3 (size, 1f, size);
     
         MeshRenderer rend = newTile.GetComponent<MeshRenderer> ();
 
         return newTile;
     }
Comment
Add comment · Show 4
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 Scruffy250 · Jul 12, 2017 at 04:16 PM 0
Share

What is the value of feildSize?

avatar image PijusVose Scruffy250 · Jul 12, 2017 at 04:37 PM 0
Share

The value is 10

avatar image PijusVose Scruffy250 · Jul 12, 2017 at 04:38 PM 0
Share

Also, should I convert my arrays to lists? would it be easier to find a tile I need?

avatar image Jwizard93 PijusVose · Jul 12, 2017 at 04:57 PM 0
Share

I think it has something to do with the hierachy. $$anonymous$$aybe try to set the parent before you set the localPosition?

setting localPosition will offset the object from it's parent. setiing position will move the object to a global position and the localPosition variable will now reflect the new offset from it's parent.

And yeah with Lists you can do alot for finding stuff more easily. Especially with Linq.

1 Reply

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

Answer by Glurth · Jul 12, 2017 at 05:01 PM

If you want your Tile at the same position as the "field" you parent it to (if not tell me and I'll delete answer):

 newField.transform.position = new Vector3 (0f, 0f, 0f);

would be incorrect becuase you assigning to the world position value. These two options would be what you need, I recommend the second (note how it is similar/dissimilar to what you do with the "fields", and THEIR parent).

 newField.transform.position = fields[x, y].transform.position; 

or

 newField.transform.localPosition = new Vector3 (0f, 0f, 0f);


PS: you are storing the built tile in an object named newField- could be a little confusing.

Comment
Add comment · Show 1 · 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 PijusVose · Jul 12, 2017 at 06:53 PM 0
Share

I am trying to make a double tile map. Inside the "Field" can be either another tile map or just a 10 by 10 cube. Not sure if I should keep my fields and their children inside lists or jagged arrays tho.

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

95 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

Related Questions

Does the gameobject brush create tiles when painting on a 2d Tilemap? 1 Answer

Hexagonal Tilemap with 3D GameObject brush. Every 2 rows it is misalligned 0 Answers

How to find the GameObject attached to a Tile? 0 Answers

Tilemap not being synced across network 0 Answers

Can I insert sets of tilemaps into a gameobject and maintain the efficiency of the tilemap system? 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