Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
This question was closed Jul 23, 2015 at 08:15 PM by Noxury for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Noxury · Jul 23, 2015 at 08:06 PM · editorinstantiateprefabgridlevel

How can I create a grid for a Leveleditor?

Hello,

I want to make a grid, but the instantiated grid-prefabs are not aligning right next to each other, they are overlapping:

Gridfail

 for(var x : int = 0; x < sizeX; x++){
     for(var y : int = 0; y < sizeY; y++){
         gridClone = Instantiate(grid, Vector3.zero, Quaternion.identity);
         gridClone.transform.position = Vector3(x,0,y);
     }
 }


gridfail.png (22.6 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 Cherno · Jul 23, 2015 at 08:15 PM 0
Share

Looks like you need to take into account the size of the prefab. Try multiplying the x and y values of the position by about 16.

 gridClone.transform.position = Vector3(x * 16,0,y * 16);

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Noxury · Jul 23, 2015 at 08:14 PM

Nevermind, I have found a solution:

 for(var x : int = 0; x < sizeX; x++){
     for(var y : int = 0; y < sizeY; y++){
         gridClone = Instantiate(grid, Vector3(x*24,0,y*24), Quaternion.identity);
     }
 }

}

Note that 24 is the width/height of the grid prefab.

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 Jessespike · Jul 23, 2015 at 08:17 PM 0
Share

Need to provide how much space is in between the instantiated objects. Can make public properties and adjust as needed:

 public float spacingX = 10f;
 public float spacingY = 10f;

then in the for-loop, multiple the position with the spacings:

 gridClone.transform.position = Vector3(x * spacingX, 0f, y * spacingY);


Note that the variable "y" is actually using the Z position. I named the property |spacingY| to keep consistent with the existing code. It should be "z".

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Prefabs are instantiated in editor but not in executable 2 Answers

Why my prefab is auto changing? 3 Answers

Add prefabs to hierarchy without game running? 1 Answer

Instantiate in Editor 1 Answer

Instantiate prefab within parameters?(Javascript) 1 Answer


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