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

Rav*_*viG 3 unity-game-engine unity5

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

ana*_*ter 7

将精灵放在任何以资源开头的文件夹中,例如我的精灵在"资源/图像/测试"中

[SerializeField] private UnityEngine.UI.Image image = null;

private void Awake()
{
    if( image != null )
    {
        image.sprite = Resources.Load<Sprite>( "Images/test" );
    }
}
Run Code Online (Sandbox Code Playgroud)

http://docs.unity3d.com/462/Documentation/ScriptReference/UI.RawImage.html http://docs.unity3d.com/ScriptReference/Resources.Load.html

  • 切记不要在资源地址中包含图像扩展名。 (3认同)