So I have a sprite game object with the sprite renderer component.
I have set the renderer to use a sprite created from a sprite sheet.
the problem im having is during runtime i want to change the sprite to use a new texture.
at the moment im doing something like this and it clears the sprite any tips
Texture2D tex = Resources.Load(“planets_2”) as Texture2D;
Carsten Germer’s answer works. I edited it a little to meet my purposes, and am not allowed to vote yet, but wanted to confirm that it works, if others are wondering.
I’m not sure if this helps, but Sprite Renderers take Sprites to render–on your Texture2D in your Assets folder, click the little arrow next to it and you get all the sprites in your spritesheet. Those are Sprites, not the original image which is a Texture2D–those are what the sprite renderer takes as its sprite.