Changing a materials emission value on mouse over?

Hi,

is it possible to change the emission value of a material on mouse over via script? I want to highlight an object when hovering over it with the mouse and I think doing so through raising the emission value could be a good option.

Anybody has ideas on how to do that or has a different approach to highlighting an object?

thanks in advance

I suppose you know how to call stuff when you mouse over an object from the last thread…

Read the example there, I suppose it should work calling m_Material.emission instead of m_Material.color.

1 Like

I find that adjusting the emission isn’t enough. Either enable and disable it like so;

    private Renderer _renderer;

    void Start ()
    {
        _renderer = GetComponent<Renderer>();   
    }

    public void OnMouseEnter()
    {
        _renderer.material.EnableKeyword("_EMISSION");
    }

    public void OnMouseExit()
    {
        _renderer.material.DisableKeyword("_EMISSION");
    }

or swap out the material.

1 Like

Thanks guys. I will try it. :slight_smile:

I got it to work. Thanks guys :slight_smile:

That is frustrating that you need to use the enable/disable keyword. By just doing a SetColor(“_EmissionColor”… I can see the emissive property change but not actually update in the viewport.