void OnCollisionEnter2D(Collision2D other) { if (isDead) { return; } bool hitDamagingObject = false; PlayerDamaging possibleDamage = other.collider.GetComponentInParent <PlayerDamaging> (); if (possibleDamage != null) { if (possibleDamage.lethal) { Die(); return; } if (possibleDamage.minVelocity == 0) { hitDamagingObject = true; } else if (other.relativeVelocity.magnitude > possibleDamage.minVelocity) { hitDamagingObject = true; } } if (hitDamagingObject) { HitByDamagingObject(other.transform); } }
protected virtual void Die() { state = State.dead; if (!fixedPosition) { rb.isKinematic = false; } anim.SetTrigger("Die"); PlayerDamaging possibleDamaging = GetComponent <PlayerDamaging> (); if (possibleDamaging != null) { Destroy(possibleDamaging); } }