Material Extensions

Set Color

This sets the color of the specified material.

Material material = new Material(Shader.Find("Standard"));

material.SetColor(Color.red);

Set Main Texture

This sets the main texture of the specified material.

Material material = new Material(Shader.Find("Standard"));

material.SetMainTexture(texture);

Set Texture Offset

This sets the main texture offset with the given value.

Material material = new Material(Shader.Find("Standard"));

material.SetTextureOffset(0.5f, 0.5f);

Set Texture Scale

This sets the main texture scale with the given value.

Material material = new Material(Shader.Find("Standard"));

material.SetTextureScale(1.5f, 1.5f);

Set Shader

This sets the shader of the specified material.

Material material = new Material(Shader.Find("Standard"));

material.SetShader(shader);

Set Rendering Mode

This sets the shader of the specified material.

Material material = new Material(Shader.Find("Standard"));

material.SetRenderingMode(RenderingMode.Transparent);

Lighten Color

This lightens the specified color by a given amount.

Color color = new Color(0.5f, 0.5f, 0.5f);

Color lighterColor = color.Lighten(0.2f);

Darken Color

This darkens the specified color by a given amount.

Color color = new Color(0.5f, 0.5f, 0.5f);

Color darkerColor = color.Darken(0.2f);

Mix Colors

This mixes two colors based on the specified amount.

Color color1 = Color.red;
Color color2 = Color.blue;

Color mixedColor = color1.Mix(color2, 0.5f);  

Invert Color

This inverts a color and returns.

Color color = new Color(0.5f, 0.5f, 0.5f);

Color invertedColor = color.Invert();

Grayscale Color

This converts the specified color to its grayscale equivalent.

Color color = new Color(0.5f, 0.5f, 0.5f);

Color grayColor = color.Grayscale();

Set Alpha

This sets the alpha (transparency) value of the specified color.

Color color = new Color(0.5f, 0.5f, 0.5f);

Color transparentColor = color.SetAlpha(0.5f);  

Last updated