- Home /
cant change standard shader emission color?
So I'm in unity 5.2.2f1 and really all I'm trying to do is set up a base class that will make objects that inherit from it highlight if the player hovers over them with the mouse. At the moment the functions seem to run on mouse enter and on mouse exit because i definitely get the debug logs out. The color it turns into should be an obnoxious bright green - mostly so theres no mistaking that its happening, but the emission color never changes from black unless I do it manually.
check out my code, is there something that I'm missing? I'm using the standard shader, and I looked at it to figure out that the emissive color property should be "_EmissionColor" but maybe I need to alter more than one field? I've also tried altering "gameObject.GetComponent ().material" in case keeping a reference like I'm doing wouldn't work but still no dice :\ . I read on some other forum that it might be the property isn't enabled? I tried enabling the keyword in awake but that hasn't helped either.
using UnityEngine;
using System.Collections;
public class InteractibleObject : MonoBehaviour
{
public Renderer objectRenderer;
public Color mouseOverColor = Color.green;
public Color baseColor;
public virtual void OnMouseEnter()
{
objectRenderer.material.SetColor("_EmissionColor", mouseOverColor);
Debug.Log("mousing over");
}
public virtual void OnMouseExit()
{
objectRenderer.material.SetColor("_EmissionColor", baseColor);
Debug.Log("mousing out");
}
private void Awake()
{
objectRenderer.material.EnableKeyword("_EMISSION");
baseColor = objectRenderer.material.GetColor("_EmissionColor");
}
}
Your answer
Follow this Question
Related Questions
Does Unity have any emissive shaders? 1 Answer
Shader - Remove Alpha before adding color 1 Answer
Simple emission shader for beast lightmaps 1 Answer
Unity HDRP, Objects not using emission 0 Answers
Can you change terrain material? 4 Answers