var newmat = AssetDatabase.LoadAssetAtPath("Assets/Materials/Univeral Render Pipeline Lit.mat", typeof(Material));
var allgameobjects = FindObjectsOfType<GameObject>();
foreach(GameObject go in allgameobjects)
{
if (go.GetComponent<Renderer>() != null)
{
if (go.GetComponent<Renderer>().sharedMaterial.name.StartsWith("Default"))
{
DestroyImmediate(go.GetComponent<Renderer>().sharedMaterial);
//Add material
go.GetComponent<Renderer>().sharedMaterial = newmat;
}
}
}
Но я думаю, вы могли бы просто изменить материал
var newmat = AssetDatabase.LoadAssetAtPath("Assets/Materials/Univeral Render Pipeline Lit.mat", typeof(Material));
var allgameobjects = FindObjectsOfType<GameObject>();
foreach(GameObject go in allgameobjects)
{
if (go.GetComponent<Renderer>() != null)
{
if (go.GetComponent<Renderer>().sharedMaterial.name.StartsWith("Default"))
{
go.GetComponent<Renderer>().sharedMaterial = newmat;
}
}
}
для ландшафта, это terrain.materialTemplate