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 Lord Moon · Feb 17, 2012 at 02:21 AM · prefabtimespawnspawner

Spawn a prefab at different objects

How do I get it so if I have multiple empty objects around with the tag "Spawner" how to I get a prefab to spawn at two random spawner tagged objects every certain amount of seconds

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

2 Replies

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

Answer by Esa · Feb 17, 2012 at 06:20 AM

You could give those spawn locations an integer ID. Then select the wanted amount of random numbers with Random.Range() and then just For-loop the list of your spawn locations. When the random number matches the spawn locations ID you spawn one there.

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
avatar image
0

Answer by Lord Moon · Feb 17, 2012 at 10:00 PM

@Esa ... I did that I made this:

     var prefab : GameObject;
 var spawn1 : GameObject;
 var spawn2 : GameObject;
 var spawn3 : GameObject;
 var spawn4 : GameObject;
 var spawn5 : GameObject;
 var spawn6 : GameObject;
 var spawn7 : GameObject;
 var spawn8 : GameObject;
 var spawn9 : GameObject;
 var spawn10 : GameObject;
 function Update () {
 }
 
 function Start () {
 SpawnerID = Random.Range(1, 10);
 
 if(SpawnerID == 1){
 
 Instantiate(prefab, spawn1.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 2){
 
 Instantiate(prefab, spawn2.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 3){
 
 Instantiate(prefab, spawn3.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 4){
 
 Instantiate(prefab, spawn4.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 5){
 
 Instantiate(prefab, spawn5.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 6){
 
 Instantiate(prefab, spawn6.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 7){
 
 Instantiate(prefab, spawn7.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 8){
 
 Instantiate(prefab, spawn8.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 9){
 
 Instantiate(prefab, spawn9.Transform, Quaternion.identity);
 
 }
 
 if(SpawnerID == 10){
 
 Instantiate(prefab, spawn10.Transform, Quaternion.identity);
 
 }
 
 }


But when I run the game I get this error: NullReferenceExpetion: Object reference not set to an instance of an object Spawnrandom.Start() (at Assets/Scriptadoodles/Spawnrandom.js 56) ...Yeah my script folder name is goofy =/

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 Lord Moon · Feb 18, 2012 at 07:59 AM 0
Share

It's fixed now, so thanks Esa

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Random Spawn, Random Prefab 2 Answers

c# Enemy's spawning over time, problem 2 Answers

How to Make an Expanding Spawn Area for Prefabs? 2 Answers

Why are my bullets shooting at an unpredictable rate? 3 Answers

How to Use Object Pooling? Is my Script Wrong? 0 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