void OnCollisionEnter2D(Collision2D col) { GameObject other = col.gameObject; if (other.name == "Player") { DamageData playerDamage = other.GetComponent <DamageData>(); if (playerDamage != null) { playerDamage.addHealth(damageData.health); Destroy(gameObject); } } }