You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
985 B
38 lines
985 B
using UnityEngine; |
|
using System.Collections; |
|
|
|
public class ME_LightCurves : MonoBehaviour |
|
{ |
|
public AnimationCurve LightCurve = AnimationCurve.EaseInOut(0, 0, 1, 1); |
|
public float GraphTimeMultiplier = 1, GraphIntensityMultiplier = 1; |
|
public bool IsLoop; |
|
|
|
private bool canUpdate; |
|
private float startTime; |
|
private Light lightSource; |
|
|
|
private void Awake() |
|
{ |
|
lightSource = GetComponent<Light>(); |
|
lightSource.intensity = LightCurve.Evaluate(0); |
|
} |
|
|
|
private void OnEnable() |
|
{ |
|
startTime = Time.time; |
|
canUpdate = true; |
|
} |
|
|
|
private void Update() |
|
{ |
|
var time = Time.time - startTime; |
|
if (canUpdate) { |
|
var eval = LightCurve.Evaluate(time / GraphTimeMultiplier) * GraphIntensityMultiplier; |
|
lightSource.intensity = eval; |
|
} |
|
if (time >= GraphTimeMultiplier) { |
|
if (IsLoop) startTime = Time.time; |
|
else canUpdate = false; |
|
} |
|
} |
|
} |