Load Texture2D converted into Sprites; How can i add them to a GameObject sucessfully?

I’m loading a lot of PNG’s generated by the computer in a folder, after that i’m loading that PNG’s like Texture2D at runtime through a function, until here, there seems to be no problem.

The problem is: How can i convert this Texture2D to Sprites in order to use them in a GameObject?

Here is the code:

public static Sprite Texture2DToSprites(this Texture2D txture2d)
                Sprite sprite = Sprite.Create(txture2d, new Rect(0, 0, txture2d.width, txture2d.height), new Vector2(0.5f, 0.5f));
                Debug.Log("Texture2D converted in Sprites Sucessfully!!");
                return sprite;
            catch (System.Exception ex)
                Debug.Log("PrepareTexture2DToSprites Error: " + ex.ToString());
                return null;

It would also be cool if you show me a way to test than the PNG’s being loaded are loaded in a correct way, however that’s not the main focus of the question, but it would help too. :wink:

Thanks for th attention.

nvm, i fix it, the problem was the name of the Sprite won’t save itself, fixing that everything works like a charm, so this converter helps a lot and also do the work, however admins, feel free to delete the question if you think is duplicated or if necesary.

Thanks a lot