banner



How To Change The Mesh In Tango

In this commodity, nosotros will run across how to change material and its properties at runtime in a unity application.

Let's set up a simple scene in unity for this commodity. I accept just added a Sphere GameObject in the empty scene.

Change Material at Runtime

We can utilize multiple materials on a GameObject in unity. You can see these materials in the Mesh Renderer component of the GameObject.

Change Material and its properties at runtime

To alter the material at runtime, add below script to the Sphere GameObject.

Change Material and its properties at runtime

We can besides change the materials assortment from the MeshRenderer component. Actually, the GetComponent<MeshRenderer>().material belongings returns the start element of the materials array only.

Change Fabric Properties at Runtime

Material properties is directly related to the shader attached to the cloth. You tin see the shader attached to the material in the Inspector Window.

Change Material and its properties at runtime

If nosotros create a new material and then unity already attaches Standard shader to information technology. However, the shader attached to the cloth can exist changed from the Inspector window and as well at runtime.

The properties of the cloth can be changed past editing shader backdrop.  You can run into the detailed listing of Shader property in the Inspector.

Change Material and its properties at runtime

Later clicking on EditShader in Inpector window, Y'all can run into the shader property proper name and its type (int, float, color etc.).

Change Material and its properties at runtime

Change Material and its properties at runtime

Modify Texture of a Textile

Change Chief Texture

Change Material and its properties at runtime

Material.mainTexture is the main diffuse texture. This can also exist inverse past "_MainTex" belongings name for the texture from unity'due south builtin standard shader. Many shaders uses more one texture. In that case, make sure to utilize right texture belongings name to modify information technology at the runtime.

You tin can apply GetTexture property to get current chief texture of the cloth.

Alter Normal Map

Normal map can also be changed by SetTexture property of the material. "_BumpMap" is holding name of the texture in the unity standard shader.

While setting the material texture using the Standard Shader, sometime you may need to use EnableKeyword to enable features of the shader earlier calling SetTexture property.

Alter Metal Texture

Change Color of the Cloth

Alter Primary fabric's color

Use Material.color belongings to go and fix the principal material colour.

The aforementioned can exist besides inverse by SetColor property. "_Color" is the belongings name of the color in the Standard shader.

Change material color at real-time

Attach below code to the GameObject.

Effect:

Enable Shader Property

Modify Emission Values

As I mentioned earlier, some of the property should be enabled commencement; then simply it can be inverse. For instance, to change the emission color, first we demand to enable Emission belongings then it's colour tin can be inverse.

Change Float Value

Many shader property tin can be changed using Cloth.SetFloat property. Example – Metaalic Range, UV Set.

Modify Metal Range

Change Shader at runtime

Utilize below code to change shader at the runtime. Make sure the shader name is correct otherwise it will throw null reference exception.

HDRP Materials

HDRP shaders has different backdrop proper name than standard unity shader. Beneath is the shader properties of "HDRP/Lit" shader.

So, while changing shader properties at runtime apply always correct property name. For instance, to alter the color, use "_BaseColor" property.

Also, while creating material brand sure to laissez passer correct shader proper name.

That's information technology for this tutorial. I hope you go an idea about how to change material and its properties at runtime in unity application. Please mail your comments for queries and feedback. Thanks for reading.

The following ii tabs change content below.

Gyanendu Shekhar is a technology enthusiast. He loves to larn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

Source: http://gyanendushekhar.com/2018/09/16/change-material-and-its-properties-at-runtime-unity-tutorial/

Posted by: delgadogated1935.blogspot.com

0 Response to "How To Change The Mesh In Tango"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel