• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C# Overriding Emission Color - Happy New Year!

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?
 
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 :(
 
Top Bottom