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 sketchers1 · Dec 20, 2011 at 03:50 AM · rigidbodyobjecttimegroupemit

Emmiter in time intervals

So i have this object that i want to be emmited in groups of 5 at time intervals of 10 seconds. What would the code be so that I can just drag in the Rigidbody(my object) into the slot to be emmited like this? Thanks in advance!!!

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
0
Best Answer

Answer by Aleron · Dec 20, 2011 at 10:09 PM

A very simple script that should roughly do what you want would be:

 using UnityEngine;

 public class MyEmitter : MonoBehaviour
 {
     public Rigidbody emittedBody;

     void Start()
     {
         InvokeRepeating( "EmitRigidBody", 10.0f, 10.0f );
     }

     void Update()
     {
         if( Input.GetMouseButtonDown(0) )
             CancelInvoke();
     }

     void EmitRigidBody()
     {
         for( int i = 0; i < 5; ++i )
         {
             Rigidbody body = Instantiate( emittedBody ) as Rigidbody;
             // Do whatever else is wanted with the rigid body
             // ...
         }
     }
 }

If you add that script as a component to a GameObject in your scene then you will be able to drag the desired RigidBody onto the 'Emitted Body' parameter of the component. Then as soon as the scene loads it will start emitting the 5 objects every 10 seconds. You can move the InvokeRepeating to whatever piece of code you want to trigger the emitting of the object., I put the CancelInvoke so that clicking the mouse button will stop the objects from being emitted, but you can move it to wherever you want to stop the creationg of the objects from.

Comment
Add comment · Show 10 · 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 sketchers1 · Dec 21, 2011 at 02:53 AM 0
Share

this gave me the error:

Assets/Scripts/CSharpScripts/Rigidbody emmiter.cs(1,26): error CS0246: The type or namespace name `$$anonymous$$onoBehaviour' could not be found. Are you missing a using directive or an assembly reference?

avatar image Aleron · Dec 21, 2011 at 03:06 AM 0
Share

Oops, sorry, it should be Rigidbody not RigidBody. I'll edit my response to have the correct info as well.

avatar image sketchers1 · Dec 21, 2011 at 03:13 AM 0
Share

The same error shows up at (2,26)?

avatar image Aleron · Dec 21, 2011 at 04:26 PM 0
Share

Sorry, I was rushing when I responded and didn't read the actual error, the script needs using UnityEngine; at the top of it to use the UnityEngine assembly and its classes (like $$anonymous$$onoBehaviour and Rigidbody). I added that the to code snippet above. I also added the casting of the Object to a Rigidbody in the Instantiate so it is the correct type.

avatar image sketchers1 · Dec 23, 2011 at 03:56 AM 0
Share

That worked! Thank you!!!!

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

6 People are following this question.

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

Related Questions

Random time activate/deactivate object 1 Answer

TimeScaling & Rigidbody problem 0 Answers

Problem with Object collision 1 Answer

Fade between group of object 1 Answer

Emitting objects at a progressive rate randomly in a 2D game 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