Scriptum/Assets/Animations/Fire/Fire.cs

54 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fire : MonoBehaviour
{
private float range = 0;
float minFlickerIntensity = 0.5f;
float maxFlickerIntensity = 1.0f;
float flickerSpeed = 4.9f;
private HardLight2D firelight;
2023-01-13 14:11:01 +01:00
private HardLight2D[] lights;
private GameObject fire;
private int randomizer = 0;
// Start is called before the first frame update
void Start()
{
2023-01-13 14:11:01 +01:00
lights = FindObjectsOfType<HardLight2D>();
List<HardLight2D> finalList = new List<HardLight2D>();
string nameToLookFor = "LightFire";
for(var i = 0; i < lights.Length; i++)
{
if(lights[i].name == nameToLookFor)
{
finalList.Add(lights[i]);
}
}
firelight = finalList[0];
//firelight = FindObjectOfType<HardLight2D>();
StartCoroutine( ChangeRange());
}
// Update is called once per frame
void Update()
{
StartCoroutine( ChangeRange());
}
IEnumerator ChangeRange()
{
if (randomizer == 0) {
firelight.Intensity = (Random.Range (minFlickerIntensity, maxFlickerIntensity));
}
else firelight.Intensity = (Random.Range (minFlickerIntensity, maxFlickerIntensity));
randomizer = Random.Range (0, 1);
yield return new WaitForSeconds(flickerSpeed);
}
}