unity-atoms/Examples/Assets/InfiniteWaves/Common/DestroyMe.cs

35 lines
782 B
C#
Raw Normal View History

2020-03-04 18:48:39 -05:00
using UnityEngine;
using UnityEngine.Assertions;
using UnityAtoms.BaseAtoms;
2020-03-17 21:04:33 -04:00
namespace UnityAtoms.Examples
2020-03-04 18:48:39 -05:00
{
2020-03-19 20:29:39 -04:00
/// <summary>
/// Script intending to destroy the GameObject it's attached to.
/// </summary>
2020-03-17 21:04:33 -04:00
public class DestroyMe : MonoBehaviour
2020-03-04 18:48:39 -05:00
{
2020-03-17 21:04:33 -04:00
[SerializeField]
FloatReference _delay = new FloatReference(-1f);
void Start()
2020-03-11 16:11:27 -04:00
{
2020-03-17 21:04:33 -04:00
Assert.IsNotNull(_delay);
if (_delay.Value >= 0f)
{
Destroy(gameObject, _delay.Value);
}
2020-03-11 16:11:27 -04:00
}
2020-03-04 18:48:39 -05:00
2020-03-17 21:04:33 -04:00
public void DestroyImmediate() => Destroy(gameObject);
2020-03-15 18:18:29 -04:00
2020-03-17 21:04:33 -04:00
public void DestroyIfZeroOfBelow(int value)
2020-03-15 18:18:29 -04:00
{
2020-03-17 21:04:33 -04:00
if (value <= 0)
{
DestroyImmediate();
}
2020-03-15 18:18:29 -04:00
}
2020-03-04 18:48:39 -05:00
}
}