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?
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?