如何从资源文件夹加载图像并将其设置为unity5中UI图像的源图像
How to load image from resource folder and set it to source image of UI Image in unity5
如何从资源文件夹加载图像并将该图像设置为 UI 图像的源图像?
将您的精灵放在任何以资源开头的文件夹中,例如我的在 "Resources/Images/test"
[SerializeField] private UnityEngine.UI.Image image = null;
private void Awake()
{
if( image != null )
{
image.sprite = Resources.Load<Sprite>( "Images/test" );
}
}
http://docs.unity3d.com/462/Documentation/ScriptReference/UI.RawImage.html
http://docs.unity3d.com/ScriptReference/Resources.Load.html
我尝试@ananonposter 回答但是 fail.But 我尝试下面的另一种方式 code:
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;
可以用!
如何从资源文件夹加载图像并将该图像设置为 UI 图像的源图像?
将您的精灵放在任何以资源开头的文件夹中,例如我的在 "Resources/Images/test"
[SerializeField] private UnityEngine.UI.Image image = null;
private void Awake()
{
if( image != null )
{
image.sprite = Resources.Load<Sprite>( "Images/test" );
}
}
http://docs.unity3d.com/462/Documentation/ScriptReference/UI.RawImage.html http://docs.unity3d.com/ScriptReference/Resources.Load.html
我尝试@ananonposter 回答但是 fail.But 我尝试下面的另一种方式 code:
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;
可以用!