Boom.cs 983 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Boom : MonoBehaviour {
  5. [SerializeField]
  6. private float radius = 1.5f;
  7. [SerializeField]
  8. private float power = 600f;
  9. public int damage;
  10. private void Start()
  11. {
  12. StartCoroutine(lifeTime());
  13. Collider[] colliders = Physics.OverlapSphere(transform.position, radius);
  14. foreach (Collider hits in colliders)
  15. {
  16. EnemyHealth enemy = hits.GetComponent<EnemyHealth>();
  17. if (hits.GetComponent<Rigidbody>() && enemy != null)
  18. {
  19. enemy.TakeDamage(damage,transform.position);
  20. hits.GetComponent<Rigidbody>().AddExplosionForce(power, transform.position, radius);
  21. }
  22. }
  23. }
  24. IEnumerator lifeTime()
  25. {
  26. while (GetComponent<ParticleSystem>().isPlaying)
  27. {
  28. yield return null;
  29. }
  30. Destroy(this.gameObject);
  31. }
  32. }