如何从资源文件夹中加载图像并将其设置为Unity5中UI Image的源图像

11

如何从资源文件夹中加载图像,并将该图像设置为 UI 图像的源图像?


请看这里:http://answers.unity3d.com/questions/892113/how-can-i-change-a-ui-image-from-a-large-list-of-i.html - Catwood
2个回答

17

6
请勿在资源地址中包含图片扩展名。 - Ghasem

2

我尝试了@ananonposter的答案,但失败了。但是我尝试了以下代码的另一种方法:

var image = new Image();
var tex = Resources.Load<Texture2D>("Sprites/transparent");
var sprite = Sprite.Create(tex, new Rect(0.0f,0.0f,tex.width,tex.height), new Vector2(0.5f,0.5f), 100.0f);
image.sprite = sprite;

It can work!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接