public static Lifetimer AddTimer(GameObject onThis, float timeInSeconds, bool callDespawn) { Lifetimer omg = onThis.AddComponent <Lifetimer>(); omg.Lifetime = timeInSeconds; omg.CallDespawn = callDespawn; return(omg); }
void Awake() { if (_firstRun || Owner.IsDead) { return; } _despawning = false; // IgnoreCollision() kindly resets itself after being deactivated+reactivated... Safe for pooling. =] foreach (Collider2D c in _myColliders) { if (c != null) { Physics2D.IgnoreCollision(c, Owner.GetComponent <Collider2D>()); } } Lifetimer.AddTimer(gameObject, Stats.Lifetime, true); Fire(_go.transform.position); }
/// <summary> /// Timed period of downage (mostly dead). Could be revived. DeSpawn after timer ends - then totally dead. /// </summary> private IEnumerator CrippleAndDie() { // Drop to a crippled state and wait. if (Stats.CrippledTime > 0) { yield return(new WaitForSeconds(Stats.CrippledTime)); } if (Stats.DeathFx) { StaticUtil.Spawn(Stats.DeathFx, transform.position, transform.rotation); } for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(false); } // Detatch the corpse model and give it an expiration timer. Stats.DeadBodyObj.SetActive(true); Lifetimer c = Stats.DeadBodyObj.AddComponent <Lifetimer>(); c.Lifetime = Stats.CorpseTime; DeSpawn(); }