I’m new to c# and I’m working in HDRP. I want to apply a material called “Generic House Mat” to all objects in the editor EXCEPT for with tag “Don’tApplyGenMat”.
I made sure of the spelling and Capitalization in addition of making sure all exceptions have the tag.
What happens that the material is applied to all the objects including those with the tag.
if (GUILayout.Button("Apply Generic Materials"))
{
Material newMat = Resources.Load<Material>("Generic House Mat");
foreach (MeshRenderer myRenderer in Resources.FindObjectsOfTypeAll<MeshRenderer>())
{
if (!myRenderer.CompareTag("Don'tApplyGenMat"))
{
myRenderer.sharedMaterials[0] = newMat;
if (myRenderer.sharedMaterials[0] == null)
{
myRenderer.sharedMaterials[0] = new Material(Shader.Find("HDRP/Lit"));
}
}
}
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
}
Anyone could help? what is wrong with this code?
Thanks in advance