Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Grenade : MonoBehaviour
- {
- //релазиация таймера
- private float time = 0;
- [SerializeField]
- private float coolDown = 3f;
- private bool isPlayed;
- [SerializeField]
- private float radius;
- void Update()
- {
- time += Time.deltaTime;
- if (time > coolDown && !isPlayed)
- {
- //взрыв
- GetComponentInChildren<ParticleSystem>().Play();
- isPlayed = true;
- ExplosionDamage(transform.position,radius);
- //уничтожение гранаты
- Destroy(this.gameObject, 0.5f);
- }
- }
- void ExplosionDamage(Vector3 center, float radius)
- {
- Collider[] hitColliders = Physics.OverlapSphere(center, radius);
- foreach (var hitCollider in hitColliders)
- {
- if(hitCollider.GetComponent<Turret>()!=null)
- {
- hitCollider.GetComponent<Turret>().ChangeHealth(-50);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement