LegitTeddyBears

Impact Explosion

May 26th, 2017
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ImpactExplosion : MonoBehaviour
  6. {
  7.     //This dictates how hard of an impact the ship can take before exploading
  8.     public int Strength;
  9.    
  10.    
  11.     void OnCollisionEnter(Collision collision)
  12.     {
  13.  
  14.        
  15.             Debug.Log("Hit!");
  16.             if (collision.relativeVelocity.magnitude > Strength)
  17.                 {
  18.                     //This destroys the gameobject the script is attached to
  19.                     Destroy(this.gameObject);
  20.                 }
  21.    
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment