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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by G-Jewel · Dec 14, 2014 at 10:04 PM · colliderparticles

[Solved] Destroy Gameobject When A Particle Collides With It

Hi there I am just working on a simple game. When the player hits a game object it explodes and sends particles out. The simple script is below.

using UnityEngine; using System.Collections;

 public class DestroyCubesBlue : MonoBehaviour
 {
     void OnCollisionEnter (Collision col)
     {
         if(col.gameObject.name == "Safecube")
         {
             Destroy(col.gameObject);
 
             SpecialEffectsHelperBlue.Instance.Explosion (transform.position);
         }
     }
 }

I want the particles to collide with enemy cubes and destroy it :D The enemy cube just as the other cube that exploded has a box collider and a rigid body attached to it and a mesh renderer (The normal cube you can create in unity).

How I call the particles when the cube gets destroyed is using a another simple script.

 using UnityEngine;
 
 /// <summary>
 /// Creating instance of particles from code with no effort
 /// </summary>
 public class SpecialEffectsHelperBlue : MonoBehaviour
 {
     /// <summary>
     /// Singleton
     /// </summary>
     public static SpecialEffectsHelperBlue Instance;
     
     public ParticleSystem BlueExplosion;
 
     void Awake()
     {
         // Register the singleton
         if (Instance != null)
         {
             Debug.LogError("Multiple instances of SpecialEffectsHelper!");
         }
         
         Instance = this;
     }
     
     /// <summary>
     /// Create an explosion at the given location
     /// </summary>
     /// <param name="position"></param>
     public void Explosion(Vector3 position)
     {
         // 
         instantiate(BlueExplosion, position);
 
     }
     
     /// <summary>
     /// Instantiate a Particle system from prefab
     /// </summary>
     /// <param name="prefab"></param>
     /// <returns></returns>
     private ParticleSystem instantiate(ParticleSystem prefab, Vector3 position)
     {
         ParticleSystem newParticleSystem = Instantiate(
             prefab,
             position,
             Quaternion.identity
             ) as ParticleSystem;
         
         // Make sure it will be destroyed
         Destroy(
             newParticleSystem.gameObject,
             newParticleSystem.startLifetime
             );
         
         return newParticleSystem;
     }
 }

All I want to do is the particles that come out destroy the enemy like a shockwave :) Thank you. I believe I have to use OnParticleCollision?

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 VesuvianPrime · Dec 15, 2014 at 01:55 AM 0
Share

I believe you also need to check a box in the inspector to enable events as well. Also, time to pimp my own package: http://forum.unity3d.com/threads/hydra-particles-a-new-open-source-particle-sytem-for-unity3d.262813/

avatar image G-Jewel · Dec 15, 2014 at 08:31 PM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class ParticleCollision : $$anonymous$$onoBehaviour {
 
     void OnParticleCollision (ParticleSystem Explosion){
         if (Explosion.gameObject.tag == "Enemy")
             Destroy(gameObject);
     }
 
 }

I made this. I tagged the particle system with a " Explosion " tag and the enemy with a Enemy tag. I attached it to the enemy but doesn't get destroyed. The particles are colliding with the enemy as I can see it bounce off. Anybody help?

I do get this error aswell

" This message parameter has to be of type: GameObject The message will be ignored. "

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by VesuvianPrime · Dec 15, 2014 at 10:02 PM

If I'm reading the error correctly, the message probably should be:

 void OnParticleCollision (GameObject other)
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 G-Jewel · Dec 15, 2014 at 10:45 PM 0
Share

Thank you VesuvianPrime. $$anonymous$$ade the change you suggested and few others and seems to be working now. Please close.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to get Particles to glide on a surface 1 Answer

how to know if an object has been englobed by particles 1 Answer

can we attach a collider for each particle emitted by a emitter 1 Answer

Rigidbody - bullets becomes bullethole image 0 Answers

How to control World Particle Collider through script 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