private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag != "Enemy" && collision.gameObject.tag != "Enemy2" && collision.gameObject.tag != "Line" && collision.gameObject.tag != "Player" && collision.gameObject.tag != "NormalShuriken" && collision.gameObject.tag != "ExplosionStar" && collision.gameObject.tag != "DamnationShuriken") { rotationSpeed = 0; rb.isKinematic = true; var emptyObject = new GameObject(); emptyObject.AddComponent <DestroyGameObj>(); emptyObject.transform.parent = collision.transform; transform.parent = emptyObject.transform; coll.enabled = false; } if (collision.gameObject.tag == "Enemy") { BaseEnemy e = collision.gameObject.GetComponentInParent <BaseEnemy>(); e.TakeDamage(damage); rotationSpeed = 0; rb.isKinematic = true; transform.parent = collision.transform.GetChild(0); coll.enabled = false; damage = 0; } if (collision.gameObject.tag == "Enemy2") { BaseShooter s = collision.gameObject.GetComponentInParent <BaseShooter>(); s.TakeDamage(damage); rotationSpeed = 0; rb.isKinematic = true; transform.parent = collision.transform.GetChild(0); coll.enabled = false; damage = 0; } }
void Explosion() { Collider[] enemies = Physics.OverlapSphere(transform.position, radius); foreach (Collider e in enemies) { BaseEnemy enemy = e.GetComponentInParent <BaseEnemy>(); if (enemy != null) { enemy.TakeDamage(damage); } BaseShooter enemy2 = e.GetComponentInParent <BaseShooter>(); if (enemy2 != null) { enemy2.TakeDamage(damage); } } }