Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

OnParticlecollision2D?

Discussion in 'Scripting' started by Magnumstar, Mar 20, 2016.

  1. Magnumstar

    Magnumstar

    Joined:
    Oct 3, 2015
    Posts:
    304
    I need to detect 2d particle collisions. I've enabled "Send collision messages" on the particle system and added the OnParticleCollision (GameObject o) method but it never hits in this method. Is 2D particle collision messaging allowed in unity?
     
  2. xqtr123

    xqtr123

    Joined:
    Jun 7, 2014
    Posts:
    20
    For me this worked:
    In the particle system, check the following:
    upload_2021-5-15_10-42-6.png

    Then add a script to this particle system with the following code:

    Code (CSharp):
    1. void OnParticleCollision(GameObject other)
    2. {
    3.      if (other.tag == "Enemy")
    4.      {
    5.           var enemy = other.GetComponent<Enemy>();
    6.           enemy.TakeDamage();
    7.      }
    8. }