我想更改默认的天空盒 Material ,所以我做了这行...之后我只看到蓝色...我的错误是什么?
素材在旁边的Assets文件夹中
Material levelMat = Resources.Load(Application.dataPath + "/testeVR.mat", typeof(Material)) as Material;
RenderSettings.skybox = levelMat;
最佳答案
the material is on the Assets folder by the away
如果您使用 Resources.Load
加载 Material ,则不能将其放置在 Asset 文件夹中。
After that I only see blue
levelMat
变量为null
。当您应用到天空盒的 Material 为空时,您会变成蓝色,您可以通过在其后添加 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 Material 放入此位置。它应该看起来像这样: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;
关于c# - 以编程方式更改天空盒 Material (c#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41325198/