- Home /
Material emission flicker using javascript
Noob here. Creating a flickering light fixture. The bulb flickers, i wanted to just tie the emission material to the flicker ive already established.
My goal is to tie the lightobject flicker and the emission material together so the material matches.
Below is my script. Forgive the noob(ness?) :)
var flickerLight : GameObject; var Brightness : float; var LightBulbMaterial : GameObject;
function Update() {
if (Random.value > 0.8 && flickerLight.GetComponent.().intensity == Brightness) { StartCoroutine ("FlickerLightTexture"); } }
function FlickerLightTexture (){
while (flickerLight.GetComponent.<Light>().intensity >= Brightness)
{
flickerLight.GetComponent.<Light>().intensity -= Time.deltaTime*30;
yield WaitForSeconds (0.1);
}
while (flickerLight.GetComponent.<Light>().intensity <= Brightness)
{
flickerLight.GetComponent.<Light>().intensity += Time.deltaTime*30;
yield WaitForSeconds (0.1);
}
flickerLight.GetComponent.<Light>().intensity = Brightness;
LightBulbMaterial.GetComponent.<Renderer>().material.emission.color.intensity == flickerLight.GetComponent.<Light>().intensity;
}
Answer by bobisgod234 · May 18, 2017 at 03:12 AM
Try:
var intensity = flickerLight.GetComponent.<Light>().intensity;
LightBulbMaterial.GetComponent.<Renderer>().material.SetColor("_EmissionColor", Color(intensity, intensity, intensity));
Your answer
Follow this Question
Related Questions
Modifying properties of the Standard shader 1 Answer
Emission changes in script don't show in game 0 Answers
Shader or Lighting problem? 0 Answers