Search Unity

Load sprite from asset (from asset store) at runtime

Discussion in 'General Graphics' started by SimRuJ, Oct 11, 2018.

  1. SimRuJ


    Apr 7, 2016
    I "bought" a free asset with icons (it includes the ".png" files) in the asset store and want to change the sprite of a button from one of the icons to another when I click on the button.

    I know that you can load a ".png" file from the "Assets/Resources" folder like this:

    myButton.GetComponent<Image>().sprite = Resources.Load<Sprite>("PathToFile");

    Is it possible to load the icons from the asset's folder that was created when I downloaded it (the path's something like "Assets/IconAsset/128x/icon1.png") at runtime or do I have to copy the files I want to "Assets/Resources" and rename them?

    What I'm looking for is doing the same thing selecting the source image in the Inspector does, except with code.