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 Sabuus · Mar 27, 2015 at 05:01 PM · collisionparticleseffects

How do I get particles to emit on collision?

I have a particle system on a coin, but when I roll over it particles won't emit. Here's the code. I've tried multiple solutions, and some may be there in comments. There's no errors on either way of doing it. but the effects won't appear. #pragma strict

 //var coinEffect : Transform;
 var Particle : ParticleSystem;
 var coinValue = 1;
 Particle.enableEmission = false;
 
 function OnTriggerEnter (info : Collider)
 {
     if (info.tag == "Player")
     {
         GameMaster.currentScore += coinValue;
         //var effect = Instantiate(coinEffect, transform.position, transform.rotation);
         Particle.enableEmission = true;
         Particle.Play();
         //Destroy(effect.gameObject, 3);
         Destroy(gameObject);
         Particle.enableEmission = false;
     }
 }
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 hexagonius · Mar 27, 2015 at 05:19 PM 0
Share

You shouldn't destroy the object the emitter is attached to, then it cannot emit. Disable Coin renderer, disable the script and destroy it after emission (like the line you commented out)

avatar image Sabuus · Mar 27, 2015 at 05:32 PM 0
Share

so remove

 Destroy(gameObject);

and bring in

 Destroy(effect.gameObject, 3);

How would I go about getting the coin to emit the particles while still disappearing when the ball collides with it? Would it be a better idea to put the particles on the ball ins$$anonymous$$d? Sorry about all of the questions. I'm new, and I'm trying to figure out how the things work as well as to get this to work.

2 Replies

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

Answer by Digital-Phantom · Mar 27, 2015 at 06:29 PM

Make an empty game object, call it effectHolder. Put your particle emitter on this object.

Then when your collision happens instantiate this object at the same position and rotation of your coin.

Now you can fade out/destroy the coin (whichever you want) and the effect will still run. (the coin will be gone but the effect will still be there)

To tidy things up and save memory just add a destroy over time script to the effectHolder and set it to destroy about half a second after the effect has finished.

Simple and effective.

:)

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 Sabuus · Mar 27, 2015 at 08:21 PM 0
Share

Thank you, I'll try that out. =)

avatar image
1

Answer by Priyanshu · Mar 27, 2015 at 06:30 PM

As @hexagonius suggested. Particles don't emit because you destroy the coin on which it is attached.

Either:

  1. Instantiate Effect in this script.

  2. Destroy GameObject in this script.

  3. Add another script to 'Effect Object' which destroys it after some seconds. Put destroy method in its start.

Or

  1. Instead of instantiating 'Effect'. Enable particle on Coin.

  2. Disable Coin Renderer. Which will give a feel of it being destroyed to the user.

  3. Destroy the Coin after some seconds from the same script. Which will destroy particle effect too.

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 Sabuus · Mar 27, 2015 at 08:22 PM 0
Share

Thank you as well. I'll be sure to keep those in $$anonymous$$d during future projects! ^.^

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get Zerg Tentacle-like effect (see example in post)? 1 Answer

Check if a pre-determinated area has particles in it? 0 Answers

OnParticleCollision equivalent as a trigger 0 Answers

How to make OnParticleCollision affect multiple GameObject 1 Answer

Instantiating a prefab facing away from it's collision 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