Overriding Emission Color - Happy New Year!

DoomPriestK

Coder
Nov 30, 2019
30
10
8
Happy New Year Guys!

So I decided it would be a good idea to make a script that lets me control emission, so I can make neon signs and such, I wanted to add Pulsing, Blinking etc, I started with this snippet of code I found below, but it doesn't work :(

First I attach the same material thats assigned to the emissive part of an object to the materials slot in the script, then using the code I needed to be able to override the emission color that material has set.

So effectively, I can just set what color the material emits, then activate the pulsing etc.

Pulsing Emission:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EmissionControl : MonoBehaviour
{

    public float frequency = 1f;
    public Material material;
    public Color emissionColor;



    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

        float glow = (2 + Mathf.Cos(Time.time * frequency));
        material.SetColor("_EmissionColor", emissionColor * glow);
        Debug.Log(material.GetColor("_EmissionColor"));
    }
}
No matter what color I choose, the material just emits whatever it has set by default :(

The reason i'm doing it this way is so I can control the color and behaviour of each emissive material on an object.

Anyone able to help out?
 
  • Like
Reactions: Master Yoda

Master Yoda

Administrator
Administrator
Verified
Jan 2, 2018
1,317
349
95
Canada
codeforum.org
Hello @DoomPriestK! I was toying with this earlier but still haven't found a solution to this. I'm going to see if someone on our C# discord group can help out! Not really experienced with C#!
 

DoomPriestK

Coder
Nov 30, 2019
30
10
8
Hello @DoomPriestK! I was toying with this earlier but still haven't found a solution to this. I'm going to see if someone on our C# discord group can help out! Not really experienced with C#!
Thanks for the help, im trying to think of another way around this but I cant really, if I wanted to do a simple blink I can just disable then re-enable the object, but when it comes to pulsing etc I need some control :(