本文主要是介绍unity给多个物体同意修改材质脚本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- 新建一个cs文件
- 导入下面我给出的代码
- 打开unity会发现提示导入,同意即可
- 选中多个要修改的物体
- unity最上方会出现custom,点击本选择assign material
- 将要添加的材质球拖进去
- 点击右下角的assign
```csharp
using UnityEngine;
using System.Collections;
using System;
using UnityEditor;public class AssignMaterial : ScriptableWizard
{public Material theMaterial;String strHelp = "Select Game Objects";GameObject[] gos;void OnWizardUpdate(){helpString = strHelp;isValid = (theMaterial != null);}void OnWizardCreate(){gos = Selection.gameObjects;foreach (GameObject go in gos){go.GetComponent<Renderer>().material = theMaterial;}}[MenuItem("Custom/Assign Material", false, 4)]static void assignMaterial(){ScriptableWizard.DisplayWizard("Assign Material", typeof(AssignMaterial), "Assign");}
}```
这篇关于unity给多个物体同意修改材质脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!