- Home /
Applying damage on enemy with OnParticleCollision (2D)
Hi guys, how do I detect if my spell effect (particle system) hit my gameObject with the "Enemy" tag? Is this even possible in 2d? If not, how do I make spells in unity with 2d pixel art? I did enable 2d collision in the particle system, but can't make it work.
ive this:
//Spell1
private void OnParticleCollision(GameObject collision)
{
EnemyHealth enemy = collision.GetComponent<EnemyHealth>();
if (collision.gameObject.tag == ("Enemy"))
{
Debug.Log("EnemyHitWithSpell");
enemy.DamageEnemy(50);
}
}
particle can be attached with Gameobject. Gameobject can be attached with colliders
Normally with 2d game. We shoot Box Collider and that Box have attached Particle System + Sprite
Oh ok, so u don't use particle systems for spells, but just moving a gameObject with a collider?
Technically yes because it is much cheaper than particle collider. Unity did support particle collider OnHit, OnColliderWithSomething if you look through all ParticleSystem Document. It is there, I have done it and it is quite intensive with lots of particles while I do it so i just gave it up and using shoot a few gameobjects ins$$anonymous$$d
And 2d particle work too but I dont remember how I did it