31 lines
642 B
C#
31 lines
642 B
C#
using UnityEngine;
|
|
|
|
// Very simple script, just takes a light on start and slowly fades it to 0
|
|
// over the duration specified.
|
|
[RequireComponent(typeof(Light))]
|
|
public class FadingLight : MonoBehaviour
|
|
{
|
|
|
|
Light lightObj;
|
|
|
|
public float duration;
|
|
public bool isFading;
|
|
|
|
float timer;
|
|
float startIntensity;
|
|
|
|
void Start()
|
|
{
|
|
lightObj = GetComponent<Light>();
|
|
startIntensity = lightObj.intensity;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
timer += Time.deltaTime;
|
|
float t = timer / duration;
|
|
t = Mathf.Clamp01(t);
|
|
lightObj.intensity = Mathf.Lerp(startIntensity, 0, t);
|
|
}
|
|
}
|