Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Need help with accessing Materials colour made by custom shader

So i made a shader by following brackey force field tutorial.and in that shader i use custom color property named"Color" reference-:"Emission Color" and after that i made a material named "Shield" out of it.but now i want to change the Shield colour via script.but i'm unable to figure out how to access the colour property of Shield.


Is there a different method to access a material with custom shader??...!!

Best Answers

  • edited May 2020 Accepted Answer

    @JIMMY_VASHI04 you can use Material.SetColor() to set a certain color, for example to set the emission do this:

    Material.SetColor(Here you should write the reference name of the emission color in a string, value);

    value is the color you want to set it to. To get a color use Material.GetColor(Here you should write the reference name of the color you want to get in a string);

    This method will return a color so you can do this:

    Color myColor = Material.GetColor(Here you should write the reference name of the color you want to get in a string);

  • edited May 2020 Accepted Answer

    In code, colors are from 0 to 1. what you can do is put the value of a color that you want between 0 and 255, then divide by 255. This will make the colors like the ones in the inspector but put in code.

    You need to write the colors in this order:

    red, green blue, alpha/transparency

    Color myColor = new Color(255/255, 255/255, 255/255, 255/255);

    This for example will give you an opaque white.

Answers

Sign In or Register to comment.