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 /
This question was closed Aug 07, 2018 at 07:51 PM by FIREICEGUY for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by FIREICEGUY · Aug 07, 2018 at 12:56 PM · unity 2dspawndistance

Spawn distance

Hello, Please telm me how to spawn objects with distance from each other? p.s. I searched it but i didn t find anything that helps me and my game is 2d

Comment
Add comment · Show 6
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 brendanperry05 · Aug 07, 2018 at 04:05 PM 0
Share

Can't you just use instantiate and definine the location of each object?

avatar image FIREICEGUY · Aug 07, 2018 at 05:06 PM 0
Share

I tried but nothing

avatar image MT369MT · Aug 07, 2018 at 05:09 PM 0
Share

Hi, could you please specify if this is a 2D or 3D game. And if you want to spawn them all in the same direction or random directions.

avatar image FIREICEGUY · Aug 07, 2018 at 05:11 PM 0
Share

$$anonymous$$y game is 2d and i want them all at same direction

avatar image brendanperry05 FIREICEGUY · Aug 07, 2018 at 05:49 PM 0
Share

Could you please post the code you are working with and show where it's failing?

avatar image FIREICEGUY · Aug 07, 2018 at 05:53 PM 0
Share

Sorry but i deleted it

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by MT369MT · Aug 07, 2018 at 05:55 PM

Hi, this script will spawn the objects on the same y position with a distance of 2 in the x axis.

 public GameObject objectToSpawn;
 public int objectCount;
 public int xPosition;
 public int Distance;

 void Start()
 {

     objectCount = 5;
     xPosition = 0;
     Distance = 2;

     for (int i = 0; i < objectCount; i++)
     {
         Instantiate(objectToSpawn, new Vector2(xPosition, 0), Quaternion.identity);
         xPosition += Distance;
     }
 }



For y axis spawning:

     public GameObject objectToSpawn;
     public int objectCount;
     public int yPosition;
     public int Distance;
 
     void Start()
     {
 
         objectCount = 5;
         yPosition = 0;
         Distance = 2;
 
         for (int i = 0; i < objectCount; i++)
         {
             Instantiate(objectToSpawn, new Vector2(0, yPosition), Quaternion.identity);
             yPosition += Distance;
         }
     }
Comment
Add comment · Show 2 · 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 FIREICEGUY · Aug 07, 2018 at 06:00 PM 0
Share

Thanks but i want them to spawn in the y axis

avatar image MT369MT · Aug 07, 2018 at 07:07 PM 0
Share

I added the script for the y axis spawning

Follow this Question

Answers Answers and Comments

91 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

Related Questions

How to use raycasting to find distance between enemy and obstacle 1 Answer

Serious performance issues 0 Answers

spawn 3 object in a row at the same time ( unity ) 1 Answer

Help with Spawning & Destroying Background Objects in 2D 2 Answers

How to spawn my gameobjects and have it disappear after i click it 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