我想更改默认的天空盒材质,所以我做了这条线......之后我只看到蓝色......我的错误是什么?
该材料在远处的资产文件夹中
Material levelMat = Resources.Load(Application.dataPath + "/testeVR.mat", typeof(Material)) as Material;
RenderSettings.skybox = levelMat;
该材料在远处的资产文件夹中
如果您使用 Resources.Load
.
之后我只看到蓝色
levelMat
变量null
是。当您应用于 Skybox 的材料为空时,您会得到蓝色,您可以通过Debug.Log(levelMat);
在其后添加来证明这一点。
Material levelMat = Resources.Load(Application.dataPath + "/testeVR.mat", typeof(Material)) as Material;
你也不能这样做。Application.dataPath
不应在函数的路径参数中使用Resources.Load
。
从您的代码中了解几件事:
1 . Resources.Load
需要一个名为Resources的特殊文件夹。在 Assets 目录中创建一个名为Resources的文件夹,然后将testeVR.mat放入其中。
2 .您不要将文件扩展名放在函数的路径参数中Resources.Load
。所以,testeVR.mat实际上应该是没有“ .mat ”的testeVR。
只需在Assets文件夹中创建一个名为Resources的文件夹,然后将testeVR材料放在此位置。它应该看起来像这样:Assets/Resources/testeVR.mat。下面的代码应该用于加载它。
Material levelMat = Resources.Load("testeVR", typeof(Material)) as Material;
现在,假设您在Resources文件夹中有另一个名为“ Mats ”的文件夹。您将使用如下所示的内容:
Material levelMat = Resources.Load("Mats/testeVR", typeof(Material)) as Material;
只需创建材料的公共变量并放置要在运行时加载的材料,或者如果您想通过某些函数加载它,请使用它
RenderSetting.sky = skyboxMat;
skyboxMat 存储了统一拖动它的材质,然后它成为你的天空盒的一部分
public Material skyboxMat;
voidstart(){ RenderSetting.skybox = skyboxMat;}