/// <summary> /// Despawns this gameObject by returning it to Pooly's prefab pool. /// </summary> public void Despawn() { if (cStartTimer != null) { StopCoroutine(cStartTimer); cStartTimer = null; } OnDespawn.Invoke(); Pooly.Despawn(transform); }
/// <summary> /// Starts a despawn timer with a random duration. /// If the timerType was set to Start.Never you can manually call this method in order to start the timer. /// <para>If durationMinimum and durationMaximum are less than or equal to zero, or if durationMinimum is greater than durationMaximum, it will trigger an instant despawn.</para> /// </summary> /// <param name="durationMinimum">Minimum duration time.</param> /// <param name="durationMaximum">Maximumt duration time.</param> public void StartTimer(float durationMinimum, float durationMaximum) { if(cStartTimer != null) { StopCoroutine(cStartTimer); cStartTimer = null; } if(durationMinimum < 0) { durationMinimum = 0; } if(durationMaximum < 0) { durationMaximum = 0; } if(durationMinimum == durationMaximum && durationMinimum == 0) { OnDespawn.Invoke(); Pooly.Despawn(transform); return; } if(durationMinimum > durationMaximum) { OnDespawn.Invoke(); Pooly.Despawn(transform); return; } cStartTimer = StartCoroutine(iStartTimer(Random.Range(durationMinimum, durationMaximum))); }
/// <summary> /// Starts a despawn timer with a set duration. /// If the timerType was set to Start.Never you can manually call this method in order to start the timer. /// <para>If the duration is less than or equal to zero, it will trigger an instant despawn.</para> /// </summary> public void StartTimer(float duration = 0) { if (cStartTimer != null) { StopCoroutine(cStartTimer); cStartTimer = null; } if (duration <= 0) { OnDespawn.Invoke(); Pooly.Despawn(transform); return; } cStartTimer = StartCoroutine(iStartTimer(duration)); }
private IEnumerator iStartTimer(float duration) { if(useRealTime) { if(despawnWaitForSecondsRealTime == null || despawnWFSRealTimeCurrentDuration != duration) { despawnWaitForSecondsRealTime = new WaitForSecondsRealtime(duration); despawnWFSRealTimeCurrentDuration = duration; } yield return despawnWaitForSecondsRealTime; } else { if(despawnWaitForSeconds == null || despawnWFSCurrentDuration != duration) { despawnWaitForSeconds = new WaitForSeconds(duration); despawnWFSCurrentDuration = duration; } yield return despawnWaitForSeconds; } OnDespawn.Invoke(); cStartTimer = null; Pooly.Despawn(transform); }
/// <summary> /// Despawns this gameObject by returning it to the Pooly pool /// This method is useful only if you have this gameObject spawned from Pooly, thus it exists in the pool. /// </summary> public void Despawn() { Pooly.Despawn(transform); }