-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoRecycle.cs
41 lines (36 loc) · 874 Bytes
/
AutoRecycle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// AutoRecycle.cs
// Last edited 7:43 PM 04/15/2015 by Aaron Freedman
using UnityEngine;
namespace Assets.PrototypingKit
{
/// <summary>
/// Automatically recycles an object after time. Destroys object if ObjectPool is not available.
/// </summary>
public class AutoRecycle : MonoBehaviour
{
public float time;
private float init;
// Use this for initialization
private void Start()
{
init = time;
Reset();
}
public void Update()
{
if (time > 0)
{
time -= Time.deltaTime;
}
else
{
Reset();
ObjectPool.Scripts.ObjectPool.Recycle(gameObject);
}
}
private void Reset()
{
time = init;
}
}
}