private void OnCollisionEnter2D(Collision2D collision) { Debug.Log("player bullet hitting: " + collision.collider.name); enemy_logic enemy1 = collision.collider.GetComponent <enemy_logic>(); if (enemy1 != null) { enemy1.take_damage(10); } enemy2_logic enemy2 = collision.collider.GetComponent <enemy2_logic>(); if (enemy2 != null) { enemy2.take_damage(10); } Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("target")) { //destroy other.gameobject Destroy(other.gameObject); //destroy bullet Destroy(gameObject); } else if (other.CompareTag("enemy")) { enemy_logic enemyhealth = other.gameObject.GetComponent <enemy_logic>(); if (enemyhealth) { enemyhealth.takedamage(10); } Destroy(gameObject); } }