【发布时间】:2018-05-07 06:27:34
【问题描述】:
我正在创建一个纹理数组,所以我正在这样做
[SerializeField] GameObject[] uitex = new GameObject[4];
void GetTextureFromServer()
{
string dealer_image = "";
var tex = new Texture2D(20, 20);
for (int i = 0; i < tzPlayInfo.Instance.bc_gametablelist.Count; i++)
{
dealer_image += tzPlayInfo.Instance.bc_gametablelist[i].dlrimage;
dealer_image += ",";
}
string[] NewLinks = dealer_image.Split(',');
for(int j = 0; j < NewLinks.Length - 1; j++)
{
Debug.Log("HERE ARE THE LINKS : " + NewLinks[j]);
new BestHTTP.HTTPRequest(new System.Uri("***********.amazonaws.com/resources" + "/dealer/pic/" + NewLinks[j]),
(BestHTTP.HTTPRequest req, BestHTTP.HTTPResponse res) =>
{
tex.LoadImage(res.Data);
}).Send();
}
for (int i = 0; i < uitex.Length; i++)
{
uitex[i].GetComponent<UITexture>().mainTexture = tex;
}
}
到目前为止我尝试的是这个
uitex[j].GetComponent<UITexture>().mainTexture = tex;
但它给了我一个数组超出范围,我不知道为什么。
这段代码的问题是它总是得到我拥有的最后一个索引,所以所有 4 个游戏对象的所有纹理都相同,这不是我想要的。有人可以帮我解决我的问题。谢谢。
【问题讨论】:
-
我认为您混淆了数组大小。
new GameObject[4]是 5 个元素。数组从 0 开始。而且uitex[j].GetComponent<UITexture>().mainTexture = tex;绝对不可能,因为j不在范围内。 -
您之前(几个小时前)问过这个问题,我将其标记为重复。您将其删除并再次询问,然后提供了重复的答案....为什么?