Advertisement
kadyr

Untitled

Sep 4th, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Grenade : MonoBehaviour
  6. {
  7. //релазиация таймера
  8. private float time = 0;
  9. [SerializeField]
  10. private float coolDown = 3f;
  11.  
  12. private bool isPlayed;
  13.  
  14. [SerializeField]
  15. private float radius;
  16. void Update()
  17. {
  18. time += Time.deltaTime;
  19. if (time > coolDown && !isPlayed)
  20. {
  21. //взрыв
  22. GetComponentInChildren<ParticleSystem>().Play();
  23. isPlayed = true;
  24. ExplosionDamage(transform.position,radius);
  25. //уничтожение гранаты
  26. Destroy(this.gameObject, 0.5f);
  27. }
  28. }
  29.  
  30. void ExplosionDamage(Vector3 center, float radius)
  31. {
  32. Collider[] hitColliders = Physics.OverlapSphere(center, radius);
  33. foreach (var hitCollider in hitColliders)
  34. {
  35. if(hitCollider.GetComponent<Turret>()!=null)
  36. {
  37. hitCollider.GetComponent<Turret>().ChangeHealth(-50);
  38. }
  39. }
  40. }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement