1.从网页加载
using UnityEngine;
using System.Collections;using System.IO;public class WWWLoadGUITex: MonoBehaviour {void Update () {
}IEnumerator Start()
{ GUITexture guiTexture = gameObject.GetComponent<GUITexture > (); string filePath = "http://mp3.zhuqu.com/static/images/water/86/867b534c61bc1c0d34667cbd92372c01.jpg"; WWW www = new WWW(filePath); yield return www ; this.gameObject.GetComponent<GUITexture >().texture = www.texture; }2.从本地加载
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start() { this.gameObject.GetComponent<GUITexture>().texture = GetPic(Application.dataPath + @"/Pictures/1.jpg"); }Texture GetPic(string filePath)
{ Texture temp = new Texture(); FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); byte[] array = new byte[fs.Length]; fs.Read(array, 0, (int)fs.Length); Texture2D _tex2 = new Texture2D(128, 128); _tex2.LoadImage(array); temp = _tex2 as Texture; return temp; } // Update is called once per frame void Update () { }}