【问题标题】:Unity - Set material from Downloaded image instead of resourcesUnity - 从下载的图像而不是资源设置材料
【发布时间】:2016-11-17 10:44:50
【问题描述】:

我可以使用以下代码成功加载保存在我的 Unity 项目中的材质:

RenderSettings.mat1 = (Material)Resources.Load("images/img1.jpg", typeof(Material));

但是,我现在正在尝试通过下载来加载外部图像。

Texture2D imgDownloaded;
    string url = "http://www.intrawallpaper.com/static/images/1968081.jpg";

void Start()
    {
        StartCoroutine(getImg());
        fucntionx ();
    }

public void functionx()
{

    RenderSettings.mat1 = (Material)imgDownloaded;

}

IEnumerator getImg()
{
    yield return 0;

    WWW dl = new WWW(url);

    yield return dl;

    imgDownloaded = dl.texture;
}

但是,我收到无法从 Texture2D 转换为 Material 的消息。

有没有办法解决这个问题?

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    试试:

    yourMaterial.mainTexture = yourTexture;
    

    一种材质由许多纹理组成,因此自然无法在它们之间进行转换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 2020-01-05
      • 2016-06-01
      • 2017-05-19
      相关资源
      最近更新 更多