Changing a Cube’s Color | Unity Tutorial

What’s a game without color? Color is so crucial in game development. Let’s learn how to change color in Unity. If you are a beginner and want to learn how to build virtual reality games, check out our Unity 3D course

Suppose we want to change the color of a cube in Unity’s Scene. Unity provides the default material “Default-Material” for the cube. To change the cube’s color, we need to create our own material.

Right-click in the Assets folder in the Project window. Select Create > Material.

As evident in the following image, a material will appear in Assets. Change the material’s name to “CubeMaterial”.

The Inspector will contain attributes of ColorMaterial. Click on the white rectangle in the “Main Maps” section under “CubeMaterial”. This will open a color picker, as you can see in the following image.

Choose a color such as red. The values of the sliders labeled “R”, “G,” “B”, and “A” will change. This is because every color can be represented as a combination of four values: red, green, blue, and alpha. The more red in a color, the higher the red value. The same goes for green and blue.

Alpha refers to a color’s transparency. A purely red color has red and alpha values of 255. Its blue and green values are 0. Give ColorMaterial a purely red color, as has been done in the following screenshot.

To assign Cube this red color, drag and drop ColorMaterial onto the cube in the Scene.

Alternatively, drag and drop ColorMaterial in the Element 0 field in the Cube’s Mesh Renderer component. The cube’s color will become red.

To learn more about Materials in Unity, check out our Unity 3D course, where you build 30 virtual reality games!

Author Profile

Alexandra Kropova
Alexandra Kropova
Writer of blog posts and books at Mammoth Interactive. Can also be found posting to Mammoth Interactive's social media.

Leave a Reply