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 heipp123 · Jun 19, 2016 at 04:53 AM · instantiateprefabtransform.position

how do i instantiate multiple object object with line change with for loop.

hi boys and girls

how do i instantiate multiple object object with line change with for loop.

i am totally noob but in documents.

  for (int i = 0; i < 10; i++)
             Instantiate(prefab, new Vector3(i * 2.0f, 0, 0), Quaternion.identity);

there is this.

so if i want instantiate 30 prefabs do i just

 for (int i = 0; i < 3; i++)
             Instantiate(prefab, new Vector3(i * 1f, 0, 0), Quaternion.identity);
         for (int i = 0; i < 3; i++)
             Instantiate(prefab, new Vector3(i * 1f, 1, 3), Quaternion.identity);
         for (int i = 0; i < 3; i++)
             Instantiate(prefab, new Vector3(i * 1f, 2, 6), Quaternion.identity);

do i do it this way or is there simpler way. and if so how do i center the prefabs.

there was this it centers the prefabs but i dont know how do i do the line change

thanks.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoseKills · Jun 19, 2016 at 09:36 AM

You already use loops to set the x coordinate. Do it for y as well. You don't really explain what you mean by centering, but if your objects are 1 unit wide like you code suggests, just don't start from 0,0 but instead from negative coordinates by a sufficient amount

 int xCount = 3;
 int yCount = 3;
 float xCentering = -(xCount - 1) / 2f;
 float yCentering = -(yCount - 1) / 2f;
 
 for (int x = 0; x < xCount; x++) {
     for (int y = 0; y < yCount; y++) {
              Instantiate(prefab, 
                    new Vector3(x + xCentering, y + yCentering, 0), 
                    Quaternion.identity);
     }
 }
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 heipp123 · Jun 19, 2016 at 10:43 AM 0
Share

thanks for the answer. but how do i put let say 4 on top 3 on middle 2 to bottom. like this.

(by center i mean like this. but your script did well(the object were in middle of screen, but how do i put them like this .) alt text so even if there is not even number it doesnt go like this. alt text

center.png (1.0 kB)
not-center.png (1.0 kB)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to teleport player to an Instantiated Prefab 1 Answer

Prefab Enemy2 to track all prefab Enemy1's Instantiates transforms: How? 1 Answer

instantiated prefab doesn't follow spawn rotation 1 Answer

How do I instantiate particles properly,How do I instantiate particles correctly? 0 Answers

Call function for instantated prefab. "Object reference not set" 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