我有用于存储图像的Web服务器。在Unity中,我可以收到一个并创建游戏对象来改变它的材料。但是,我想收到最大号码。四个图像。 1分钟后,我想收到最大号码。四个图像再次。此外,如果服务器中有两个图像,我只想创建两个新的游戏对象并更改它们的材质。如果有三个,只需创建三个。我怎么能这样做,任何人都可以帮助我?这是Unity中的代码:
void Start () {
StartCoroutine (LoadImage ());
}
IEnumerator LoadImage(){
filename = "image" + k.ToString () + ".png";
url = "https://wwwfoodparadisehk.000webhostapp.com/" + filename;
WWW www = new WWW (url);
yield return www;
if (www.error != null) {
Debug.Log (www.error);
} else {
Debug.Log (k);
path = "Assets/MyMaterial" + k.ToString () + ".mat";
k = k + 1;
material = new Material (Shader.Find ("Sprites/Default"));
AssetDatabase.CreateAsset (material, path);
Debug.Log (AssetDatabase.GetAssetPath (material));
material.mainTexture = www.texture;
GameObject newPaperInstance = Instantiate (newpaper) as GameObject;
newPaperInstance.transform.Find ("Plane001").gameObject.GetComponent<Renderer> ().material = material;
}
}