# How can I change the color of an object at runtime?

I wish to have the shader effect as in the game 'The stack' by ketchapp

As you can see, the color of the objects as well as the skybox keep changing.

I'm completely c# noob and trying my best to find shaders to replicate the effect. But I can't find anything.

How can I change the color of an object at runtime?

• We do not allow questions which ask for off-site resources, but we do answer how to solve specific problems. I rewrote your question to fit this website. – Philipp Aug 3 '16 at 8:12
• Thank you so much for going extra mile than just answering the question, Philipp. – Bhoopalan Thaati Aug 4 '16 at 3:32

You can change the color of an object with a very simple C# script on the object.

First the quick and dirty solution to make an object red:

GetComponent<Renderer>().material.color = Color.red;


This changes the first color property of the first material of the object to RGB #ff0000. When you would like to set a specific color property of a specific material, check out Renderer.materials and Material.SetColor.

Why is this solution dirty? Because what it actually does internally is to create a complete copy of the material, then change the color value on it and then assign the new material to the object. This is not just slow, it also means that the object now has an own material and no longer shares its material with all other objects which use the same material asset.

A far more elegant solution is to use a material property block:

 MaterialPropertyBlock props = new MaterialPropertyBlock();