48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CandleIntensityAnimation : MonoBehaviour
|
|
{
|
|
private Light LightIntensity;
|
|
private float StartIntensity;
|
|
|
|
[SerializeField] private float _radius = 0.1f;
|
|
[SerializeField] private float _speed = 5f;
|
|
[Range(0, 1)]
|
|
[SerializeField] private float _randomIntensity = 0.2f;
|
|
|
|
void Awake()
|
|
{
|
|
LightIntensity = GetComponent<Light>();
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
StartCoroutine(FlameAnimation());
|
|
}
|
|
|
|
IEnumerator FlameAnimation()
|
|
{
|
|
StartIntensity = LightIntensity.intensity;
|
|
|
|
while (true)
|
|
{
|
|
float lastIntensity = LightIntensity.intensity;
|
|
float randomIntensity = StartIntensity * Random.Range(1 - _randomIntensity, 1 + _randomIntensity);
|
|
|
|
float time = 0f;
|
|
|
|
while (time < 1f)
|
|
{
|
|
LightIntensity.intensity = Mathf.Lerp(lastIntensity, randomIntensity, time);
|
|
|
|
time += Time.deltaTime * _speed;
|
|
yield return null;
|
|
}
|
|
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|