• 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 /
avatar image
0
Question by lalalanni · Jul 30, 2019 at 05:19 AM · spawnpositions

spawning gameObjects into different formations

I was wondering how I might go about spawning gameObjects in different pre-specified formations. I am trying to spawn 5 gameObjects into a random formation: i) 5 objects aligned horizontally across top of screen, OR ii) horizontally aligned across middle of screen, OR iii) horizontally aligned across bottom of screen, OR iv) V formation pointing upwards, OR v) V formation pointing downwards (example attached). Then, after a button press, these gameObjects spawn into another formation (chosen randomly). Would I start by creating an array of formations somehow? And how might I go about spawning my gameObjects into these formations? Any help would be greatly appreciated!

alt text

formations-example.png (29.0 kB)
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
1
Best Answer

Answer by Kennai · Jul 30, 2019 at 10:06 AM

Hello, @lalalanni !
The easiest way is:

  1. Create empty game object and name it "Formation 1"

  2. add 5 childs empty game objects

  3. Place childs as one of your possible formation - in a line or in V-formation

  4. go to p.1 and create another formation

  5. Once you've created all possible formations, you will have a list of game objects "Formation 1", "Formation 2" and so on.

  6. Create a new script with a parameter List of GameObject, in Inspector view assign all your formations to this list

  7. Now you are ready to spawn your game objects by randomly choose index of a list, get child's positions and copy this positions to your 5 game objects.

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 lalalanni · Jul 31, 2019 at 12:50 AM 1
Share

Thanks very much!!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

111 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 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

Best way to place a Line Renderer into scene... 1 Answer

transform.position.x ? 1 Answer

How to create a spawn point 1 Answer

Instantiate when Online or Offline. 0 Answers

How can i delete an item from an array after being used? (So, it won't be repeated) 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges