Creating materials

As we said, materials are the skin of a model and provide its distinctive look. In the following recipe, we will create two materials that show the difference between a diffuse and transparent material.

Getting ready

As we add an entirely new type of asset to our project in this recipe (didn't we tell you that we were going to create many?), we need to create a folder to store our materials. Open Unity and get ready to follow the instructions of the next recipe!

How to do it...

  1. From the Project panel, select the Assets folder, then click anywhere and select Create | Folder, as shown in the following screenshot:
    How to do it...
  2. Name the folder Materials, then double-click to open it.
  3. Right-click anywhere on the panel and select Create | Material, as shown in the following screenshot:
    How to do it...
  4. Name the material as filled, then repeat this operation to create another material and name it Transparent. At this point, you should have two gray materials in your Materials folder, one named filled and the other named Transparent.
  5. Select filled. In Inspector, check that Shader is set to Texture under Unlit. This way, our materials won't be affected by light and will simply shine.
    How to do it...
  6. Click once on the Textures folder in the Project panel.
  7. With filled selected in the Inspector window, drag and drop firstTexture onto the empty Texture field, as shown in the following screenshot:
    How to do it...
  8. Now select transparent and repeat the dragging operation with secondTexture.
  9. This time, check that the Shader field is set to Unlit/Cutout, as shown in the following screenshot:
    How to do it...
  10. You can act on the Alpha cutoff slider to adjust the transparency of the black squares on the checker texture, from null to total. The following screenshot shows how the material preview should look:
    How to do it...
  11. Add two cubes to your scene. This can be done by navigating to GameObject | Create Other from the top menu, as shown in the following screenshot:
    How to do it...
  12. Duplicate the cube or create another so that you end up with two cubes in the scene. We don't need to add a light to our scene, as we set out materials as Unlit, which means they are not actually affected by light at all.
  13. Now drag the material named filled onto one cube and transparent onto the other. The following screenshot shows the result you should get:
    How to do it...

How it works...

By getting the info about transparency from the grayscale of secondTexture and setting transparent as an Unlit/Transparent Cutout material, we caused the checkered cube to appear empty where the dark squares were.

There's more...

Unity offers the possibility to define several other material types, allowing the use of normal and specular maps and many other effects to improve the look of your models. A detailed analysis of all such materials would go beyond the scope of this chapter about importing 2D assets, so we will stop here. We will delve more into materials in the later chapters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.157