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
0
Question by Bmarlyman21 · Sep 30, 2013 at 01:28 PM · spawnpointsrandomizing

How do you spawn 10 objects between multiple points?

Okay, so basically i have 15 sites on my map, and 10 objects that i'd like to spawn randomly between the 15 sites. I'm kind of new to scripting so I don't even know where to start.

Comment
Add comment · Show 2
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 ShadoX · Sep 30, 2013 at 03:10 PM 0
Share

The easiest would probably be to place empty gameObjects at those 15 spots, add them to some list and then spawn your objects by randomly picking one of the empty gameObjects from the list.

for example: http://stackoverflow.com/questions/2706500/how-to-generate-random-int-number-c

http://www.dotnetperls.com/list or http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx

avatar image vexe · Sep 30, 2013 at 03:18 PM 0
Share

@ShadoX: I'd organize that in an answer :) with a simple example of how he'd do it and including this.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Owen-Reynolds · Sep 30, 2013 at 03:24 PM

Programming isn't super easy. In art class, best way to draw humans is to start with regular solids, pitchers, ... for practice. Best way to write a "spawn random objects" might be to program a bunch of easier stuff first. But...

Figure out a way to make and "know about" a bunch of points. Maybe 4 at first, to make testing easier. Simplest way is make a sphere Prefabs with the colliders removed. That gives you something you can place and see. Turn the meshRenderer off to hide them later (so they are really just empties.)

In the script, most people use a global Transform[] Spots; and manually load that up in the Inspector (that's C#)

Then figure out how to spawn an object at one exact spot, like (0,0,0). Then figure out how to spawn at Spots[0].position. Then figure out how to roll dice to pick a random spot 0 to Spots.Length-1 and spawn there. Then retest with 15 spots. Then decide if you want to repeat a point. To not repeat any is trickier -- look up shuffling.

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 Owen-Reynolds · Sep 30, 2013 at 08:24 PM 1
Share

That's my point. I think this is too difficult for your very first program$$anonymous$$g exercise. Pick something easier. You'll learn stuff. Eventually you'll work to up knowing enough for this one.

Even if someone wrote an exact solution (which is frowned on,) you'd still have to learn enough to be able to make little changes to it. Which you do by starting on easier problems.

avatar image Visual Programmer · Sep 30, 2013 at 09:12 PM 0
Share

Here's some reading material to get yourself started.

Array

Vector3

Random.Range

Instantiate

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

17 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

Related Questions

how to freeze a random position? 1 Answer

How do you spawn multiple prefabs within a certain distance from each other from one spawn point? 2 Answers

Player spawn point not working. 0 Answers

Spawned prefabs not keeping their Look At funtion 2 Answers

How to prevent multiple spawns from a single spawn point? 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