27 lines
761 B
C#
27 lines
761 B
C#
using UnityEngine;
|
|
|
|
namespace IllOmen
|
|
{
|
|
/// <summary>Varies a light's intensity with noise so it reads as a candle flame.</summary>
|
|
[RequireComponent(typeof(Light))]
|
|
public class CandleFlicker : MonoBehaviour
|
|
{
|
|
[SerializeField] private float baseIntensity = 6f;
|
|
[SerializeField] private float flickerAmount = 1f;
|
|
[SerializeField] private float flickerSpeed = 7f;
|
|
|
|
private Light candleLight;
|
|
|
|
private void Awake()
|
|
{
|
|
candleLight = GetComponent<Light>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
float noise = Mathf.PerlinNoise(Time.time * flickerSpeed, 0f);
|
|
candleLight.intensity = baseIntensity + (noise - 0.5f) * 2f * flickerAmount;
|
|
}
|
|
}
|
|
}
|