void OnCollisionEnter2D(Collision2D col) { audioData.Play(0); if (col.gameObject.tag == "Enemy") { EnemyStats stats = col.gameObject.GetComponent <EnemyStats>(); stats.ChangeHealth(damage); Destroy(this.gameObject); } //this.GetComponent<Rigidbody2D>().velocity *= 2; }
void OnCollisionEnter2D(Collision2D col) { audioData.Play(0); if (col.gameObject.tag == "Enemy") { EnemyStats stats = col.gameObject.GetComponent <EnemyStats>(); stats.ChangeHealth(damage); } ifCollided = true; Destroy(this.gameObject); }
private void BulletHit(RaycastHit2D hit) { if (playerBullet) { EnemyStats enemyStats = hit.collider.gameObject.GetComponent <EnemyStats>(); if (enemyStats != null) { enemyStats.ChangeHealth(-harmfulObject.damage); harmfulObject.tryDestroy(); } } else { PlayerStats playerStats = hit.collider.gameObject.GetComponent <PlayerStats>(); if (playerStats != null) { playerStats.ChangeHealth(-harmfulObject.damage); harmfulObject.tryDestroy(); } } }