Advertisement
Ychenik

Easy granate

Apr 8th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class granate : MonoBehaviour
  6. {
  7.     public GameObject explotion;
  8.     public float expForce = 400;
  9.     private void OnCollisionEnter(Collision collision)
  10.     {
  11.         GameObject exp = Instantiate(explotion, transform.position, transform.rotation);
  12.         Collider[] colliders = Physics.OverlapSphere(transform.position, 10);
  13.  
  14.         for(int i = 0; i < colliders.Length; i++)
  15.         {
  16.             if (colliders[i].gameObject.tag == "Explosion")
  17.             {
  18.                 colliders[i].gameObject.GetComponent<Rigidbody>().AddExplosionForce(expForce, collision.contacts[0].point - collision.contacts[0].normal, 100);
  19.             }
  20.             if (colliders[i].gameObject.tag == "Woda")
  21.             {
  22.                 colliders[i].gameObject.GetComponent<Rigidbody>().AddExplosionForce(expForce, collision.contacts[0].point - collision.contacts[0].normal, 100);
  23.             }
  24.             if (colliders[i].gameObject.tag == "Cube")
  25.             {
  26.                 colliders[i].gameObject.GetComponent<Rigidbody>().AddExplosionForce(expForce, collision.contacts[0].point - collision.contacts[0].normal, 100);
  27.             }
  28.         }
  29.  
  30.         Destroy(gameObject);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement