Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 dreal · Mar 15, 2010 at 04:39 AM · characterparticlesdestroyparticlesystem

How do i destroy a character and have a particle effect after?

I have a enemy character that comes at me and once i kill him he falls and disappears. I created a particle effect that suppose to appear right after he disappears,as if he turns into dust. how would i go about doing this? I tried to create an empty game object and attach the particle system to it which didn't work. Then i tried to attach the particle system to enemy character and i still can't get it to work. Please Help!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Jaap Kreijkamp · Mar 15, 2010 at 05:45 AM

  • make a gameobject
  • add particle effect to it with auto-destruct on
  • make a prefab of this gameobject
  • optionally test if particle object does it's job (create new scene, place gameobject in view, press start, you should see the effect and object should clean up)
  • modify your script to instantiate the effect:


var dieEffectsPrefab : Transform;

function Die() { Instantiate(dieEffectsPrefab, transform.position, transform.rotation); Destroy(gameObject); }

To respond to one of the comments, the Auto-destruct should destroy the gameobject the particle is a component of so it's not really necessary to add the delayed Destroy. If you do add the delayed Destroy, you should destroy the gameObject, not the transform you get back from the Instantiate. So code would become:

var dieEffectsPrefab : Transform; var timeOut : float = 3.0;

function Die() { var instance = Instantiate(dieEffectsPrefab, transform.position, transform.rotation); Destroy(instance.gameObject, timeOut); Destroy(gameObject); }

But once again, when you check the auto-destruct in the particle animator, you don't need this extra code.

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 duhprey · Mar 15, 2010 at 07:15 AM 0
Share

I think the useful thing I found in addition to Jaap's response is using: var inst = Instantiate(dieEffectsPrefab...) Destroy(gameObject) Destroy(inst, 3)

That Destroy(inst, 3) would destroy the particle effect after 3 seconds so that it had its chance to blow up and then it'd disappear.

avatar image
3

Answer by backalleyJack · Jun 01, 2012 at 07:19 AM

This works for me, using ParticleSystem. Code is attached to the object we are destroying:

 public ParticleSystem DestructionEffect; //assign prefab in editor or elsewhere
                                          //in code
 void Explode()
     {
        //Instantiate our one-off particle system
        ParticleSystem explosionEffect = Instantiate(DestructionEffect) 
                                         as ParticleSystem;
        explosionEffect.transform.position = transform.position;

        //play it
        explosionEffect.loop = false;
        explosionEffect.Play();
 
        //destroy the particle system when its duration is up, right
        //it would play a second time.
        Destroy(explosionEffect.gameObject, explosionEffect.duration);

        //destroy our game object
        Destroy(gameObject);
     
     }
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 whydoidoit · Jun 01, 2012 at 08:04 AM 0
Share

Particle Systems normally destroy themselves, meaning that the timed destroy is normally not necessary.

You answer has turned up three times because it was held in a moderation queue, that happens when you have low $$anonymous$$arma and have just joined the site. Someone with enough $$anonymous$$arma will probably eventually delete the extra answers, but it would save them the effort If you did it :)

avatar image backalleyJack · Jun 02, 2012 at 06:42 PM 0
Share

Done, sorry about that.

When I tested this, the particle always seemed to remain and replay after its duration ran out, even with loop = false. I didn't see any auto-destroy flag or anything like that in the API either. I'm curious, how do you get them to destroy themselves?

avatar image
0

Answer by bienphong416 · Oct 19, 2015 at 10:45 AM

you ca'nt detroy other object in present script of other object , you must add a script into particle effect example:void start() { Detroy(gameobject,3); }

3 : the time detroy;

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 bienphong416 · Oct 19, 2015 at 08:12 AM 0
Share

use function Detroy(), example i have cube and a effect when 2 cube collision together then function OnCollisionEnter() be enforcement c# public GameObject effect; void OnCollisionEnter() { Instantiate(effect,transform.position,transform.rotation); Destroy(effect,3f); Destroy(gameObject); }

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

2 People are following this question.

avatar image avatar image

Related Questions

How to destroy / hide a single particle? 2 Answers

How to destroy live particle in Shuriken 1 Answer

How to destory any object that collides with a particle in a particle system?? 1 Answer

How to destroy particle gameobject after its finished? 2 Answers

animate particle effect with existing clip animaton 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