Home > other >  How to push material to Mesh Renderer
How to push material to Mesh Renderer

Time:09-27

How can I push material at the end of meshRender Array?

Here is my code

[SerializeField] private MeshRenderer meshRenderer;


public void PushMaterial (Material newMaterial)
{
  if (!meshRenderer) return;
  meshRenderer.materials [meshRenderer.materials.Length - 1] = newMaterial;
}

here is what I'm getting in inspector

NOTE!

I'm sure the newMaterial reference is not null and also meshRenderer.material = newMaterial is working but I want to push it at the end of the Array.

CodePudding user response:

Like this:

Solution

Duplicate from Unity Forms

  • Related