Change Texture2d of sprite within sprite renderer during runtime

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;

Rect rec = new Rect(0,0,10,10);

Vector2 pivot = new Vector2(0.5f,0.5f);

Sprite newPlanet = Sprite.Create(tex,rec,pivot);

transform.GetComponent().sprite = newPlanet;

Same-ish question here. Would love to see the answer to Kaldhus question.

Solved:
Once I got to it, I quickly figured it out. Some code from my prefab that may be of help for future searchers:

I hold the sprites in public variables, so they can be set in the inspector.
The Tap… logic is code for using TouchScript.

public class blockHandler : MonoBehaviour {
  public Sprite greenSprite;
  public Sprite yellowSprite;
  public Sprite redSprite;
  public int actuState = 3; // default, can be set in inspector
  private SpriteRenderer myRenderer;

  void Start () {
    myRenderer = gameObject.GetComponent<SpriteRenderer>();

    if (actuState == 1) {
      myRenderer.sprite = greenSprite;
    }
    else if (actuState == 2) {
      myRenderer.sprite = yellowSprite;
    }
    else if (actuState == 3) {
      myRenderer.sprite = redSprite;
    }
    GetComponent<TapGesture>().StateChanged += tapHandler;
  }
  
  void tapHandler (object sender, GestureStateChangeEventArgs e)
  {
    if (e.State == Gesture.GestureState.Recognized)
    {
      if (actuState == 3) {
        actuState = 2;
        myRenderer.sprite = yellowSprite;
      }
      else if (actuState == 2) {
        actuState = 1;
        myRenderer.sprite = greenSprite;
      }
    }
    
  }

}

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.