Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Rocket : MonoBehaviour
  6. {
  7. [HideInInspector]
  8. public float radius;
  9. [HideInInspector]
  10. public float dmg;
  11. [HideInInspector]
  12. public LayerMask LayerMask;
  13. [HideInInspector]
  14. public GameObject explosion;
  15. [HideInInspector]
  16. public AudioClip explosionSound;
  17.  
  18. float rocketLife;
  19. float destroyAfter = 50;
  20. Vector3 wybuch;
  21.  
  22. void Update()
  23. {
  24. rocketLife += Time.deltaTime;
  25. if(rocketLife > destroyAfter)
  26. {
  27. Destroy(this.gameObject);
  28. }
  29. }
  30.  
  31. private void OnCollisionEnter(Collision collision)
  32. {
  33. ContactPoint contact = collision.contacts[0];
  34. Collider[] hitColliders = Physics.OverlapSphere(contact.point, radius, LayerMask);
  35. wybuch = contact.point;
  36. wybuch.y = wybuch.y + 1f;
  37. GameObject explosionInstantiated = (GameObject)Instantiate(explosion, wybuch, Quaternion.identity);
  38. explosionInstantiated.GetComponent<Explosion>().explosionSound = explosionSound;
  39. print("XD");
  40. print(contact.point);
  41. foreach (Collider col in hitColliders)
  42. {
  43. col.SendMessage("AddDamage", dmg, SendMessageOptions.DontRequireReceiver);
  44. }
  45. Destroy(this.gameObject);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement