How to load image from resource folder and set that image to source image of UI Image?
Place your sprite in any folder that begins with resources, e.g. mine is in "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
I try @ananonposter answer but fail.But I try another way by below 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;
It can work!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With