Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by jigwiz · Jul 04, 2017 at 02:21 AM · instantiate3dparticlesshooter

How do I destroy a single particle when it collides with a certain object

I have spheres that are instantiated when I press fire. These spheres are being shot at a particle system. I want the individual particle that is struck by the sphere to be destroyed when the sphere touches it. Selecting trigger doesn't work in particle system module, because though the particles are destroyed by the sphere placed in the scene they are not destroyed when the instantiated sphere touches them.

Here is the GetParticles script I'm using:

 public class GetParticles : MonoBehaviour {
     ParticleSystem m_System;
     ParticleSystem.Particle[] m_Particles;
     public float m_Drift = 0.01f;
 
     private void LateUpdate()
     {
         InitializeIfNeeded();
 
         // GetParticles is allocation free because we reuse the m_Particles buffer between updates
         int numParticlesAlive = m_System.GetParticles(m_Particles);
 
         // Change only the particles that are alive
         for (int i = 0; i < numParticlesAlive; i++)
         {
             m_Particles[i].velocity += Vector3.up * m_Drift;
         }
 
         // Apply the particle changes to the particle system
         m_System.SetParticles(m_Particles, numParticlesAlive);
     }
 
     void InitializeIfNeeded()
     {
         if (m_System == null)
             m_System = GetComponent<ParticleSystem>();
 
         if (m_Particles == null || m_Particles.Length < m_System.main.maxParticles)
             m_Particles = new ParticleSystem.Particle[m_System.main.maxParticles];
     }
 }

Here is the Particle Trigger script I'm using:

 public class TriggerScript : MonoBehaviour
 {
 
     public ParticleSystem ps;
  
 
     public List<ParticleSystem.Particle> enter = new List<ParticleSystem.Particle> ();
     public List<ParticleSystem.Particle> exit = new List<ParticleSystem.Particle> ();
 
 
     void OnEnable()
     {
         ps = GetComponent<ParticleSystem>();
     }
 
 
     void OnParticleTrigger()
     {
 
         
         int enterParticleNumber = ps.GetTriggerParticles (ParticleSystemTriggerEventType.Enter, enter);
         int exitParticleNumber = ps.GetTriggerParticles (ParticleSystemTriggerEventType.Exit, exit);
 
     
 
         // iterate
         for (int i = 0; i < enterParticleNumber; i++)
         {
             ParticleSystem.Particle p = enter[i];
 
             //put event here
 
 
 
         }
         for (int i = 0; i < exitParticleNumber; i++)
         {
             ParticleSystem.Particle p = exit[i];
             p.startColor = new Color32(0, 255, 0, 255);
             exit[i] = p;
         }
 
         // set
         ps.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter);
         ps.SetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit);
     }
 }

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

0 Replies

· Add your reply
  • Sort: 

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

124 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 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 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 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 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 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

How do execute explosion when instantiated object hits a particle? 1 Answer

How do you Instantiate particles using Photon? 1 Answer

Particle rotation problems in Unity 2017.1.0f3 2 Answers

How would I instantiate particles at random positions,How would I Instantiate the particles at random positions 0 Answers

Collisions only working in the editor but not in the build 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