Advertisement
Guest User

ExplosionTimedDestoryUnity

a guest
Apr 26th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. /// <summary>
  5. /// Explosion destroy.
  6. /// This script sets a timed destroy counter.
  7. /// </summary>
  8.  
  9. public class ExplosionDestroy : MonoBehaviour {
  10.  
  11.     //Variables Start
  12.  
  13.     private Transform myTransform;      //Quick Reference
  14.     private float expireTime = 5;       //The lifetime of the explosion (GameObject)
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18.         //As soon as the explosion is created start a countdown to destroy it
  19.         StartCoroutine (DestroyMyselfAfterSomeTime ());
  20.     }
  21.    
  22.     // Update is called once per frame
  23.     void Update () {
  24.    
  25.     }
  26.  
  27.     IEnumerator DestroyMyselfAfterSomeTime()
  28.     {
  29.         //Wait for the timer to count up to the expireTime and then destory the projectile
  30.         yield return new WaitForSeconds (expireTime);
  31.         Destroy (myTransform.gameObject);
  32.        
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement