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 NDJoshi · Mar 25, 2014 at 11:09 AM · instantiategeneration

How to Instantiate objects automatically???

Hello friends, I have Total 10 objects. Which have to be generated automatically and randomly. There has to be specific time interval in between object generation. If any of those object touch the character, they should be destroyed, or else if they pass through a particular position they should be destroyed. I just don't know what to do. Please if any one can help me out, It will be a great help to me. Thanks in advance.

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 suribe · Mar 25, 2014 at 11:15 AM 0
Share

Please, specify better... your objects are Prefabs? Do you want to do this in code or only in the editor?

  • For instancing through code, you can use GameObject.Instantiate.

  • For doing it after a period of time, call Invoke with a time parameter

  • For destroying things when touching the player, use Colliders

avatar image NDJoshi · Mar 25, 2014 at 11:28 AM 0
Share

First of all thanks for the reply. Actually i want to make an array of all those objects and then instantiate them randomly. I have got the logic to destroy the objects. But, not for the instantiate. It will be a great help if you can help me with the code. Thanks

1 Reply

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

Answer by Dmitry Pyalov · Mar 25, 2014 at 11:26 AM

  1. Create a prefab of your game object.

  2. Store the reference to prefab in your generation script or put the prefab in Resources folder and load it via Resources.Load()

  3. Instantiate game objects from prefab via Object.Instantiate

  4. ???

  5. PROFIT

Comment
Add comment · Show 6 · 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 NDJoshi · Mar 25, 2014 at 11:28 AM 0
Share

First of all thanks for the reply. Actually i want to make an array of all those objects and then instantiate them randomly. I have got the logic to destroy the objects. But, not for the instantiate. It will be a great help if you can help me with the code. Thanks

avatar image Dmitry Pyalov · Mar 25, 2014 at 11:43 AM 0
Share

Create an array of GameObject in your master script. Fill it with prefabs you want. Then randomly choose one of them and instantiate it via Object.Instantiate.

Or put the prefabs inside Resources folder :) $$anonymous$$ake a list of resource paths and then Resource.Load them and instantiate via Object.Instantiate.

avatar image NDJoshi · Mar 25, 2014 at 11:45 AM 0
Share

Thanks for taking interest brother. I have already made an array of prefabs. But, i don't know how to generate objects randomly from that array.

avatar image NDJoshi · Mar 25, 2014 at 11:46 AM 0
Share

If you can help me with the script it will be a great help for me.

avatar image Dmitry Pyalov · Mar 25, 2014 at 11:53 AM 0
Share

Something like:

 var prototype = this.prefabs[Random.Range(0, prefabs.Length)];
 var gameObject = (GameObject)Object.Instantiate(prototype, new_location, new_rotation);

Sorry, don't have Unity opened right now. New_location and new_rotation should be random generated by you somehow, e.g. using Random class.

Show more comments

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

22 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

Related Questions

Instantiate GameObject on local axis rather than world axis 1 Answer

2D Platform Generation: Spawning Platforms Consecutively 3 Answers

There is a generation lag 1 Answer

Generate cubes in 5 areas 1 Answer

Checking if object intersects? 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