【发布时间】:2026-02-01 21:50:01
【问题描述】:
我是 Unity3d 和 C# 的初学者,经过数小时搜索解决方案(并根据文档在 C# 中构建 XML 阅读器)后,我遇到了这个问题:
我有两个预制平面标记为“测试”,我想在加载图像时将来自 URL 的图像显示为纹理。
飞机在 loadImageFromURL.cs 中有一个空的 Start 和 Update 方法和这个公共方法:
public IEnumerator changeTexture(string url){
Debug.Log (url);
WWW www = new WWW (url);
yield return www;
renderer.material.mainTexture = www.texture;
}
然后我有一个空的 gamobject,它在 Start() 方法中收集图像 URL,然后我这样做:
IEnumerator Start () {
WWW www = new WWW("http://example.com/xmlfile.rss");
yield return www;
stream = new StringReader(www.text);
/*Here I do all the XML stuff, it provides the URLs from the rss feed there is no error in it*/
picture = GameObject.FindGameObjectsWithTag("test");
loadImageFromURL sc = (loadImageFromURL)picture[0].GetComponent(typeof(loadImageFromURL));
//here I call the function
sc.changeTexture(URLs[2]);
}
当我只是传递 URL 并返回 null 时;在 changeTexture 方法中,它在我 Debug.Log 时显示 url。当 WWW 线路在那里时,就像什么都没有发生。同样,这个完全相同的 WWW 代码与 seen in Unity reference too 一样完美运行
所以我很确定我对 WWW 有一些不明白的地方。
【问题讨论】: