Unity中 测试从服务器获取的图片

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Http : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
		StartCoroutine("RequestServer");
	}


	public IEnumerator RequestServer()
	{
		string url = "http://127.0.0.1:8090";
		WWW www = new WWW (url);
		yield return www;
		if (string.IsNullOrEmpty (www.error)) {
			
			string resultData = www.text;
			Debug.Log (resultData);

			Texture texture = www.texture;
			Debug.Log (texture.name);
			if (texture != null) {
				Debug.Log("texture不为空");

				GameObject subObj = GameObject.CreatePrimitive (PrimitiveType.Quad);  
				Material mat = new Material (Shader.Find("Transparent/Diffuse"));    
				mat.mainTexture = texture;  
				subObj.GetComponent ().material = mat; 

			} else {
				Debug.Log ("texture 是空的");
			}
		}else{
			Debug.Log (www.error);
		}
	}
}

承接ARKit案例开发/宣传Demo开发/游戏开发  QQ:2118590660

ARKit入门到精通系列 (视频教程地址)

http://edu.manew.com/user/98138​​​​​​​

你可能感兴趣的:(Unity)