Advertisement
AndrewRosyaev

Explosion .cs

Jul 1st, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Explosion : MonoBehaviour
  5. {
  6.     public float Radius;
  7.     public float Force;
  8.     void Update ()
  9.     {
  10.         Collider[] hitColliders = Physics.OverlapSphere(transform.position, Radius);
  11.         for(int i=0; i<hitColliders.Length; i++)
  12.         {
  13.             if(hitColliders[i].GetComponent<Wall>())
  14.             {
  15.                 hitColliders[i].GetComponent<Wall>().Dead();
  16.             }
  17.             if(hitColliders[i].CompareTag("CanBeRigidbody"))
  18.             {
  19.                 if(!hitColliders[i].rigidbody)
  20.                 {
  21.                 hitColliders[i].gameObject.AddComponent<Rigidbody>();
  22.                 }
  23.                 hitColliders[i].rigidbody.AddExplosionForce(Force, transform.position, Radius, 3.0F);
  24.             }
  25.         }
  26.         Destroy(gameObject,0.2f);
  27.     }
  28.     void OnDrawGizmos()
  29.     {
  30.         Gizmos.color = Color.red;
  31.         Gizmos.DrawWireSphere(transform.position,Radius);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement