private void OnTriggerEnter(Collider other) { if (other == target.GetComponent <Collider>()) { Vector3 direction = other.transform.position - transform.position; target.Explode(direction, force); Destroy(gameObject); } }
protected virtual void Explode() { CameraShake.CameraShakeEvent.Invoke(data.shakeDuration, data.shakeMagnitude); if (GetType() == typeof(ThrowingBomb)) { Owner.gameObject.GetComponent <PlayerController>().PlayThrowingExplosion(); } else { Owner.gameObject.GetComponent <PlayerController>().PlayBigExplosion(); } GameObject effect = Instantiate(data.explosionEffect, transform.position, transform.rotation); Destroy(effect, 1f); Collider[] colliders = Physics.OverlapSphere(transform.position, data.radius); List <BombInteractable> bombInteractables = new List <BombInteractable>(); foreach (Collider hit in colliders) { BombInteractable bi = hit.GetComponent <BombInteractable>(); if (bi) { bombInteractables.Add(bi); Vector3 difference = bi.transform.position - transform.position; difference.y = data.upForce; Vector3 direction = Vector3.Normalize(difference); bi.Explode(direction, data.force, Owner); } } // Adds hits to StatTracker Owner.StatTracker.AddStat(new CountStat(Owner, "hits", bombInteractables.Count)); Owner.StatTracker.AddStat(new RecordStat(Owner, "mostHitsWithOneBomb", bombInteractables.Count)); if (bombEffect != null) { bombEffect.Activate(bombInteractables); } Destroy(gameObject); }