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 Rocket : MonoBehaviour
- {
- [HideInInspector]
- public float radius;
- [HideInInspector]
- public float dmg;
- [HideInInspector]
- public LayerMask LayerMask;
- [HideInInspector]
- public GameObject explosion;
- [HideInInspector]
- public AudioClip explosionSound;
- float rocketLife;
- float destroyAfter = 50;
- Vector3 wybuch;
- void Update()
- {
- rocketLife += Time.deltaTime;
- if(rocketLife > destroyAfter)
- {
- Destroy(this.gameObject);
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- ContactPoint contact = collision.contacts[0];
- Collider[] hitColliders = Physics.OverlapSphere(contact.point, radius, LayerMask);
- wybuch = contact.point;
- wybuch.y = wybuch.y + 1f;
- GameObject explosionInstantiated = (GameObject)Instantiate(explosion, wybuch, Quaternion.identity);
- explosionInstantiated.GetComponent<Explosion>().explosionSound = explosionSound;
- print("XD");
- print(contact.point);
- foreach (Collider col in hitColliders)
- {
- col.SendMessage("AddDamage", dmg, SendMessageOptions.DontRequireReceiver);
- }
- Destroy(this.gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement