Search Unity

Changing Emission value in code

Discussion in 'Image Effects' started by TheMonkeysaur, Aug 31, 2017.

  1. TheMonkeysaur

    TheMonkeysaur

    Joined:
    May 2, 2017
    Posts:
    52
    I have a series of simple cubes, and when the player selects a cube emission becomes enabled and the current color of the cube is used for the emission color, however I would like to turn the emission value up from 1 to 2.

    Setting my prefab cube emission to 2 does not seem to make any difference. I am turning off emission at Start, and enabling it only when selected=true and this seems to set the emission value to 1.

    I have searched around but I can't seem to find an explanation for how to set the emission value, I've messed with my code for setting the emission color and enabling it, but there doesn't seem to be an
    "_EmissionScale" for me to manipulate.

    This is my code for setting the emission color:

    Code (csharp):
    1. this.GetComponent<Renderer>().material.SetColor("_EmissionColor", myColor);
    The only thing I have found to try for the emission value is this, but it doesn't seem to have any effect:

    Code (csharp):
    1. this.GetComponent<Renderer>().material.SetFloat("_EmissionScaleUI", 2f);
    I couldn't see any "_EmissionScale" which I can use, any help would be really appreciated!

    Thanks!
     
  2. TheMonkeysaur

    TheMonkeysaur

    Joined:
    May 2, 2017
    Posts:
    52
    I haven't solved this yet, can anyone tell me if it is even possible to change the emission value at runtime?