Apply Materials, Shaders And Textures To Objects In Unity

Introduction 

 
This article shows how to apply materials, shaders, and textures to objects in Unity
 
Prerequisites
 
Unity Environment version 2018.4.25f1
 

Create the project

 
Apply Materials, Shaders And Textures To Objects In Unity
 
I just opened Unity and I have this main scene that doesn't have any objects in it yet. I'm about to create just a rectangular prism object in Unity, and then I'm going to add some textures and shaders. The first thing I'm going to do is create the objects.
 

Create a cube in Unity

 
Click on game object 3d and then I'm going to create a cube.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
I have a cube here. I'm going to grab the scale tool and I'm just going to turn this into a bit of a wall.
 
Apply Materials, Shaders And Textures To Objects In Unity 
 
I'm just going to add color to it and then I'm going to go a bit further and use an image as a texture. It's going to be like a brick wall kind of pattern. To create a texture, we can go to assets and then create it. Then we create a material, not a texture. Go to assets, create, and then material.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Rename the material as red in the scene view.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Pick a color and it'll be red. In Unity, materials contain properties and textures, so material contains properties and textures, and shaders dictate which properties and which textures a material can have. If we click on this material here, we can have a look at the inspector. We can look at different properties. Under the shader there are a few different types of shaders that we can choose from, so right now it's just a standard. Just go with the standard shader.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Click on this color box to pick a color. This material is called red, so I'm going to pick a nice red color from the color picker.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Drag and drop materials to Object in the Scene View.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Create a brick wall texture. What I'm going to do is go to assets, click on create, and then material.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Rename the material as a brick wall in the scene view.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Right-click on Assets. Select Create >> Folder.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Rename the Folder as a texture in the scene view.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
I'm going to go into my texture folder and I've already got a texture file open here. It's just a jpg image and just a brick wall image, but it's a repeating pattern, so it's tileable. You can look up images on Google and you can search for different images such as grass patterns or brick wall patterns or water patterns. But make sure if you want a lot, you repeat these patterns or images over an object. Make sure you search for them and just add the keyword of either seamless or tileable repeating just do you get a nice repeating pattern like that alright so I'm going to drag that into my textures folder here in Unity. 
 
Apply Materials, Shaders And Textures To Objects In Unity
 
Click on the brick wall material and change the shader form standard to diffuse. There are a few different options here, you can see it diffuses the default shader. With the diffuse shader, light is evenly distributed across the surface of the object that you apply to. It basically just gives the object a shiny surface. There are a few other ones as well, so bump diffuse and specular. We are going to choose the diffuse option.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
All right, now with diffuse you can give it color, but we have this option here as well to pick a texture so if we click on select you can see that that brick wall texture is already there so you can double click on bricks and now you can see this material has a brick wall texture the few other properties here as well so I got tiling. So basically, we're tiling, which is how we can define how often the texture repeats across the x and y axes of the object. There's also offset, which defines if a gap will exist between the edges of the object and its texture.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
This brick wall material we can drag it onto the object and now this object has a brick wall texture.
 
Apply Materials, Shaders And Textures To Objects In Unity
 
The material of an object by draging a material from the assets folder straight on the object okay there you go and when you change the properties of material here in the inspector panel. It will apply to all of those objects that have the material in the scene.
 

Summary

 
I hope you understood how to apply materials, shaders, and textures to objects in Unity


Similar Articles