Converting a string name to a sprite

To Mods: – I had to create two topics on this because the first one wasn’t going live. Sorry about that.

Hi, I need to convert a string to a sprite.

I tried making an array of 99 sprites, but it causes the scene load time to be slow (this scene is loaded often)

I decided to instead, have an array of 99 strings, pull a string from the array and convert it to sprite… But can’t seem to find anywhere how to do this:


String imagename = “Thetestimage”;

gameObject.Sprite = imagename;

instead of (which is the way I think most people will suggest doing this)

public Sprite spritename ;

gameObject.Sprite = spritename;

Thanks for you time.

are you looking for an image on a hard drive ? on the internet? in your assets folder? peeps can answer here quickly if you give us this info.

If you want to use function
Resources.Load(), you have to put the
files in a folder named “Resources”.

Thank you! That worked perfect :slight_smile:

Sprite DaSprite = Resources.Load(StringUsed, typeof(Sprite)) as Sprite;//randomstring converted to sprite