Hi,
I have particle effect prefabs and i instantiate one of them at the position of Player in my game. What i try to do is when i set active instantiated particle prefab true, enemies will be destroyed that on collision with particle effect.
Everything else work well except particle collision. I have no idea how to get it work. I shared images of inspector and how it looks in scene. I also shared my script. Can anyone help me to get it work ?
(Note: The script attached to Player.)
Thanks…
public void OnParticleCollision(GameObject other)
{
if (other.gameObject.tag == "Enemy")
{
Destroy(other.gameObject);
}
}
What you have posted looks correct.
Try adding a Debug.Log to the function to see if it runs at all? Maybe the tag == “Enemy” line is wrong?
1 Like
I instantiate 3d effect at the position of 2d sprite and enemies are 2d sprites too. Is this the reason that it’s not working ?
I put a 3d cube which has collider and enemy layer, on the scene and tried again. It’s still not working. Is using OverlapCircle2d more advanced for me ? Since i couldn’t get it work, ive to find any else way to move on. 
To collide with 2d sprites you’ll need to set the collision module to 2d mode.
But not sure why it’s not working even with a 3D cube for you.
Also, what did you find out based on my first reply? Is the function being called at all?
Yes i have tried the way you said and nothing appears in console when test it by Debug.Log. I don’t know why. Maybe i put the script in wrong object.
All in all, i used overlapCircle2d and set its radius by same value effect’s scale has. Now it’s working the way i want. I’d like to move on with particleCollision method though. Thanks.
You can use the script on either the Particle System or the collider.