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 firestoke · Oct 21, 2015 at 12:03 PM · tiled

How to create tiled map correctly?

Hey guys, I am newbie in Unity, I start to develop a Unity project TODAY. Sorry about the stupid question I ask, but I really don't know where I do wrong.

first, I follow this tutorial and try to create a tiled map. Then I have a C# script called GameManager which will create the tiled map by the following code:

 int rows = 5;
 int columns = 10;
 private Transform shopHolder;

 void initDirts() {
         shopHolder = new GameObject ("Shop").transform;
         for (int x=0; x<columns; x++) {
             for(int y=0; y<rows; y++ ) {
                 GameObject obj = dirts[Random.Range(0, dirts.Length)];
                 GameObject instance = Instantiate(obj, new Vector3(x,y,0f), Quaternion.identity) as GameObject;
                 instance.transform.parent = shopHolder;
                 Debug.Log(instance);
             }
         }
     }


But when I run the project to see result, it shows like this: alt text

The position of each tile is too far, I expect them should be stay together. But I don't know how to do that. Can someone give some direction?

Here is the GameObject in prefab and its setting in my Unity project, each of the sprite size is 32x32 pixels. alt text

setting.png (34.1 kB)
error-tiled-map.png (58.7 kB)
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 firestoke · Oct 22, 2015 at 08:17 AM 0
Share

I seems knows the reason. Yesterday, I download the tutorial's assests from Unity Store. And I change the tile sprite source to the tutorial's sprite sheet. Then it looks fine!

As the screenshot, the left one is my own sprite sheet, the right one is tutorial's sprite sheet. Both of the sprite I using is 32x32 pixels. The difference is, I create my sprite sheet by TexturePacker. alt text

When I drag the sprite I use for tile to the scene. You can see the difference, the sprite from my own sprite sheet is much smaller. The tutorial's sprite just fits a grid size. I really don't know why this happen???? alt text

spritesheet.png (105.1 kB)
screen-shot-2015-10-22-at-120451-pm.png (9.5 kB)

2 Replies

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

Answer by firestoke · Oct 22, 2015 at 05:22 AM

oh my god! I know why......................
Because the sprite sheet generated by TexturePacker, the default value of "Pixels Per Unit" is 100. However, the value of tutorial's sprite sheet is 32. alt text

I change the value from 100 to 32, then everything is fine now! alt text

I am really newbie in Unity... Orz. Sorry about this stupid question again. =.,=


screen-shot-2015-10-22-at-12425-pm.png (17.7 kB)
screen-shot-2015-10-22-at-11848-pm.png (32.3 kB)
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
avatar image
1

Answer by Jessespike · Oct 21, 2015 at 05:20 PM

Pixels and World Space units aren't the same. So you need to either resize the sprites or change their position when they are instantiated.

 GameObject instance = Instantiate(obj, new Vector3(x,y,0f), Quaternion.identity);
 instance.transform.localScale = new Vector3(4f, 4f);    // change the scale in runtime


  
 float positionScale = 0.25f; // scale the distance between sprites
 GameObject instance = Instantiate(obj, new Vector3(x*positionScale ,y*positionScale ,0f), Quaternion.identity) as GameObject;

Alternatively, you can use a Quad. Since quads are sized for world space, I mean, you wont have to scale anything, quads can be aligned in a simple loop like in your example.

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How To Change Which Edge Tiled Images Snap To? 0 Answers

Can Tiled place prefabs instead of just textures? 0 Answers

unity ui darker than actual assets 0 Answers

3DS object applied material shown repeated 0 Answers

Best way to generate tiled ground? 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