Advertisement
LegitTeddyBears

BoomBoom

May 25th, 2017
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BoomBoom : MonoBehaviour
  6. {
  7.     //How long till the bomb is active after spawning
  8. `   public float m_PrimeTime = 2;
  9.     //How long has the bomb exsisted
  10.     public double m_PreDetTime;
  11.     //The prefab the actually explodes
  12.     public GameObject Explosion;
  13.     //How much force it takes to explode
  14.     public int Impact_Threshold;
  15.    
  16.  
  17.     private void OnCollisionEnter(Collision collision)
  18.     {
  19.         //Has the bomb existed for long enough to be primed?  If yes continue
  20.        if (m_PreDetTime >= m_PrimeTime)
  21.         {
  22.             //Is force of impact greater than the Impact_Threshold?  If so continue
  23.             if (collision.relativeVelocity.magnitude > Impact_Threshold)
  24.             {
  25.                 //Object is created where the bomb is on impact, this creates the explosion before despawning
  26.                 GameObject BoomHolder = Instantiate(Explosion, this.transform.position, this.transform.rotation) as GameObject;
  27.                 //Destroy the Bomb
  28.                 Destroy(this.gameObject);
  29.                 //Destory the BoomHolder after 5 Seconds (Make this slightly longer than your clip)
  30.                 Destroy(BoomHolder, 5.0f);
  31.             }
  32.         }
  33.     }
  34.  
  35.     void Update()
  36.     {
  37.         m_PreDetTime += Time.deltaTime;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement