Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Change Brightness in emission color during runtime

Discussion in 'Scripting' started by Onilut, Nov 14, 2015.

  1. Onilut

    Onilut

    Joined:
    Aug 10, 2015
    Posts:
    36
    How to change the brightness of emission colour in runtime.

    I do this to change the emission color: "cubotemporal.transform.FindChild("anillo").GetComponent<Renderer>().material.SetColor("_EmissionColor", Color.blue);" (cubotemporal is a reference to a game object which has a child named "anillo" whose color I change in runtime).

    But i dont know how to change the brightness, everytime i change the color it resets to 1.

    here a picture https://gyazo.com/7ef3362f25c413fe306a44318e298b0f (I want to change the number at the right of Emission).

    Hope you guys can help me, i'm stuck with this.
     
  2. ehdeekay

    ehdeekay

    Joined:
    Nov 9, 2012
    Posts:
    18
    I'm no expert but when I look at the Shader, which I am assuming is Standard Shader, you can see that the Emission color has an Alpha for the Brightness.

    Code (csharp):
    1. _EmissionColor ("Color", Color) = (0,0,0,1)
    What you are setting by using "...Color.blue);" is telling it to go to Color blue, but defaulting back to 1.

    Try this as a variable for Color.blue instead.

    Code (csharp):
    1. BlueColor = new Color(0,0,255,8);
    If I'm wrong someone correct me. ;)
     
  3. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    Maybe lerp the 2 colors?
     
  4. Onilut

    Onilut

    Joined:
    Aug 10, 2015
    Posts:
    36
    Hi again. You were not that wrong... basically the 4th number has not any effect (or at least... I haven't seen it). But if you want a blue with a number of brightness "8" you just have to write this.
    Code (CSharp):
    1. Color blueColor = new Color (0, 0, 8);
    Hope this can help somebody else. Thanks for the help :D

    Edit: Ok, but this don't let me to combine colors, if I write for example: (3.2f, 3.2f, 8f) i get a white color, i can't make the blue more clear, i need basically something that let me modify only the brightness, so i can use the new Color to make any color I want.

    Any idea? :(
     
    Last edited: Nov 16, 2015
  5. ehdeekay

    ehdeekay

    Joined:
    Nov 9, 2012
    Posts:
    18
    That seems weird. It's RGBA. When you are doing 3.2f and getting white you are maxing out. 1f would be like 255 I believe.