Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by Tyler 2 · Nov 06, 2010 at 05:39 AM · randomobjectsspawningplacement

Random object spawn?

Hello, how would I spawn a series of objects (enemies or collectables) at pre-set points? For example: If I set up 100 spawn points and there are 25 collectables, how would I do that? Also, how would I just make it so that the objects spawn anywhere within a boundary set in unity (like enemies spawning anywhere in a cube space that is set as the level boundary and not just at set points)

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

Answer by Jesse Anders · Nov 06, 2010 at 07:52 PM

If you have a set of specific spawn points, one approach would be the following. Store the spawn points in a suitable container, such as an array. Then, store a separate, dynamic list of 'free spawn point indices' (the generic List container would be a good choice for this).

The 'free index' list should initially contain the indices of all the spawn points (0-99 in your example). Every time you want to spawn an item, select an element from the 'free index' list randomly (e.g. using Random.Range()). Spawn an object at the spawn point, and then remove that index from the list. If objects can continue to spawn over the course of the game, you'll probably also need to add spawn point indices to the 'free index' list once the spawn point becomes available again. (Note that this approach is based on the assumption that you only want one object at any one spawn point at any one time.)

For the second question, you can just use Random.Range() to assign a random value in the appropriate range to the x, y, and z elements of the position of the new object.

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

No one has followed this question yet.

Related Questions

Placing trees randomly across a large terrain 1 Answer

How do I randomly create 2 objects, each with a different shape and color? 1 Answer

How do I make a game object spawn several times in semi-random locations? 1 Answer

Make Objects spawn within different screen sizes 0 Answers

Generating pickups randomly 3 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