HDRP Horror light flicker and GI fade off
So i'm trying to have one of those "flickering" light effect and i just can't get it to work. The script works fine, but when i "deactivate" the light, the GI "fades out" instead of just going black. It does look like the GI just takes forever to disappear and i can't find a solution.
The script i'm using ( deactivating the children Light component and changing the shader emission color to black at once) :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class light_flicker_02_random : MonoBehaviour
{
private Material _Matos;
private Color Black = new Color(10f, 10f, 10f, 255f);
private Color White = new Color(212f, 212f, 212f, 255f);
private Color Blue = new Color(0f, 0f, 255f, 255f);
[SerializeField]
private float minTimeOn = 0f;
[SerializeField]
private float maxTimeOn = 1.5f;
[SerializeField]
private float minTimeOff = 0f;
[SerializeField]
private float maxTimeOff = 0.1f;
private float changeTime = 0;
private Light _Light;
void Start()
{
_Matos = GetComponent<Renderer>().material;
_Matos.SetColor("_EmissiveColor", White);
_Light = GetComponentInChildren<Light>();
}
void Update()
{
if (Time.time > changeTime)
{
_Light.enabled = !_Light.enabled;
if (_Light.enabled)
{
changeTime = Time.time + Random.Range(minTimeOn, maxTimeOn);
_Matos.SetColor("_EmissiveColor", White);
}
else
{
changeTime = Time.time + Random.Range(minTimeOff, maxTimeOff);
_Matos.SetColor("_EmissiveColor", Black);
}
}
}
}
I tried using "just lights" but it's really the same. Using just the shader emissive gives me weird results and i doubt it's really optimized. Not sure where to go from here, and suggestion is welcome. Thanks in advance :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612190922im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Tip on properly lighting kitchen scene with opening drawers 0 Answers
Global Illumination at Runtime 0 Answers
Problem with GI 0 Answers
Ambient occlusion vs global illumination? 0 Answers
Confusion about Mixed lighting 0 Answers