Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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!

DoomPriestK

Active Coder
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.

[CODE title="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"));
}
}[/CODE]

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#!
 
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 :(
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom