public void OnCollisionEnter(Collision collision) { Rigidbody targetRB = null; CellBody target = null; Chasis player = null; if (collision.gameObject.tag != Tags.playerTag) { Collider[] targets = Physics.OverlapSphere(transform.position, _explosionRadius); for (int i = 0; i < targets.Length; i++) { if (targets[i].gameObject.tag == Tags.playerTag) { player = targets[i].GetComponent <Chasis>(); } else { target = targets[i].GetComponent <CellBody>(); } targetRB = targets[i].GetComponent <Rigidbody>(); if (targetRB != null) { targetRB.AddExplosionForce(_explosionForce, transform.position, _explosionRadius, 0, ForceMode.Impulse); Debug.Log("EXPLODE"); if (target != null) { target.TakeDamage(_dmg); } if (player != null) { player.TakeDamage(_dmg); } } Destroy(gameObject); } } }
void Detonate() { Rigidbody targetRB = null; CellBody target = null; Chasis player = null; Collider[] targets = Physics.OverlapSphere(transform.position, _explosionRadius); for (int i = 0; i < targets.Length; i++) { if (targets[i].gameObject.tag == Tags.playerTag) { player = targets[i].GetComponent <Chasis>(); } else { target = targets[i].GetComponent <CellBody>(); } targetRB = targets[i].GetComponent <Rigidbody>(); if (targetRB != null && targetRB != _rb) { targetRB.AddExplosionForce(_explosionForce, transform.position, _explosionRadius, 0, ForceMode.Impulse); if (target != null) { target.TakeDamage(_mineDamage); } if (player != null) { player.TakeDamage(_mineDamage); Debug.Log(player.gameObject.name); } } Destroy(gameObject); } }