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

Question OnParticleTrigger() enter particles always zero

Discussion in 'Scripting' started by Xhitman, Dec 19, 2020.

  1. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    Particle setting:
    Colliders: None
    Inside: Ignore
    Outside: Ignore
    Enter: Callback
    Exit Ignore

    Code (CSharp):
    1. void OnParticleTrigger()
    2.     {
    3.         // get
    4.         int numEnter = PS.GetTriggerParticles(ParticleSystemTriggerEventType.Enter,enter);
    5.  
    6.      
    7.         Debug.Log(Time.time + "  " + numEnter);
    8.         for (int i = 0; i < numEnter; i++)
    9.         {
    10.             ParticleSystem.Particle p = enter[i];
    11.  
    12.             int LayerMask = 1 << Constants.Layer_BodyPart;
    13.             Collider[] hits = Physics.OverlapSphere(p.position, 1f, LayerMask);
    14.             foreach (Collider c in hits)
    15.                 Debug.Log(Time.time + "  " + c);
    16.         }
    17.     }
     
  2. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    I find the problem, the colliders have to be the "target collider".

    But I don't know there are many colliders moving in the 3d space in my game, I cannot fill the target collider list.