0

I am making a game in unity where you launch a ball into enemies and on collision they get damaged. I want to add a particle effect at the point where the 2 objects collide but I cant figure out how to get the location. Here is the collision script for the enemy:

   private void OnCollisionEnter2D(Collision2D collision)
     {
         if(collision.relativeVelocity.magnitude > 7)
         {
             damage = damageConstant * collision.relativeVelocity.magnitude;
             health -= damage;
             CreatePopup(gameObject.transform.position, damage);
     
         }
         if(health <= 0)
         {
             Destroy(gameObject);
         }
     }

If you can also explain the solution that would be great for the future

shingo
  • 18,436
  • 5
  • 23
  • 42
Flimzy
  • 11
  • 2

1 Answers1

0
private void OnCollisionEnter(Collision collision)
{
    var contactAmount = collision.contacts;
    collision.GetContact(0);
}

you can get contact amount and position of contact by get collision.GetContact(int index) method.