以编程方式更改天空盒 Material (c#)
Change Skybox Material Programmatically (c#)
我想更改默认的天空盒 material 所以我做了这行...之后我只看到蓝色...我的错误是什么?
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 实际上应该是 testeVR 没有“.mat”.
只需在 Assets 文件夹中创建一个名为 Resources 的文件夹,然后将 testeVR material 在这个地方里面。它应该看起来像这样:Assets/Resources/testeVR.mat。应该使用下面的代码来加载它。
Material levelMat = Resources.Load("testeVR", typeof(Material)) as Material;
现在,假设您有另一个名为“Mats”的文件夹,它位于 Resources 文件夹中。您将使用如下内容:
Material levelMat = Resources.Load("Mats/testeVR", typeof(Material)) as Material;
只需创建 material 的 public 变量并放置要在运行时加载的 material ,或者如果您想通过某些函数加载它,请使用此
RenderSetting.sky = skyboxMat;
skyboxMat 存储了 material 将它统一拖动,然后它就成为你的天空盒的一部分
public Material skyboxMat;
voidstart(){ RenderSetting.skybox = skyboxMat;}
我想更改默认的天空盒 material 所以我做了这行...之后我只看到蓝色...我的错误是什么?
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 实际上应该是 testeVR 没有“.mat”.
只需在 Assets 文件夹中创建一个名为 Resources 的文件夹,然后将 testeVR material 在这个地方里面。它应该看起来像这样:Assets/Resources/testeVR.mat。应该使用下面的代码来加载它。
Material levelMat = Resources.Load("testeVR", typeof(Material)) as Material;
现在,假设您有另一个名为“Mats”的文件夹,它位于 Resources 文件夹中。您将使用如下内容:
Material levelMat = Resources.Load("Mats/testeVR", typeof(Material)) as Material;
只需创建 material 的 public 变量并放置要在运行时加载的 material ,或者如果您想通过某些函数加载它,请使用此
RenderSetting.sky = skyboxMat;
skyboxMat 存储了 material 将它统一拖动,然后它就成为你的天空盒的一部分
public Material skyboxMat;
voidstart(){ RenderSetting.skybox = skyboxMat;}