cwisbg

ExploderBg

Mar 4th, 2017
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ExploderBg : MonoBehaviour {
  5.     public GameObject ExplosionPrefab;
  6.     public int HitCount = 1;
  7.     private int HitTracker = 1;
  8.     public float ImpactThreshold = 15.0f;
  9.     public float LifeSpan = 10.0f;
  10.  
  11.     void OnCollisionEnter (Collision collision) {
  12.         if (collision.relativeVelocity.magnitude > ImpactThreshold){
  13.             HitTracker += 1;
  14.         }
  15.     }
  16.     void FixedUpdate(){
  17.         if (HitTracker > HitCount) {
  18.             var bullet = (GameObject)Instantiate (
  19.                 ExplosionPrefab,
  20.                 transform.position,
  21.                 transform.rotation);
  22.             Destroy (gameObject);
  23.             Destroy (bullet, LifeSpan);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment