UGUI更换图片的三种方法

//方法一: Image/pic 在 Assets/Resources/目录下 
Image _myImage; 
void Start()
{
    _myImage.sprite = Resources.Load("Image/pic", typeof(Sprite)) as Sprite;
}

//方法二:mySprite 为外部指定的图片资源
Image _myImage; 
Sprite _ISprite; void Start()
{
  _myImage.sprite = ISprite
}
//方法三 
Image myImage; void Start () { StartCoroutine(GetImage()); }
IEnumerator GetImage()
{

string url = "http://www.5dbb.com/images/logo.gif";
WWW www = new WWW(url);
yield return www;

if (string.IsNullOrEmpty(www.error))
{
Texture2D tex = www.texture;
Sprite temp = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0)); myImage.sprite = temp;
}
}
复制代码

 

posted @ 2018-11-23 18:01  大旗1401  阅读(939)  评论(0编辑  收藏  举报