MiniGame-PushPush/Assets/Epic Toon FX/Scripts/ETFXLightFade.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2023-10-04 20:20:04 +09:00
using UnityEngine;
namespace EpicToonFX
{
public class ETFXLightFade : MonoBehaviour
{
public enum OnLifeEnd { DoNothing, Disable, Destroy }
[Header("Seconds to dim the light")]
public float life = 0.2f;
public OnLifeEnd onLifeEnd = OnLifeEnd.Destroy;
private Light li;
private float initIntensity;
// Use this for initialization
private void Start()
{
li = GetComponent<Light>();
if (li != null)
{
initIntensity = li.intensity;
}
}
// Update is called once per frame
private void Update()
{
if (li != null)
{
li.intensity -= initIntensity * (Time.deltaTime / life);
if (li.intensity <= 0f)
{
switch (onLifeEnd)
{
case OnLifeEnd.DoNothing:
// Do nothing
break;
case OnLifeEnd.Disable:
li.enabled = false;
break;
case OnLifeEnd.Destroy:
Destroy(li);
break;
}
}
}
}
}
}