// Declare a private SpriteRenderer.
SpriteRenderer spriteRenderer;
// Set the new Sprite in the Inspector.
[SerializeField] private Sprite new_Sprite;
void Start()
{
// Get the SpriteRenderer Component from the GameObject.
spriteRenderer = GetComponent<SpriteRenderer>();
}
// public function to call and change the sprite.
public void ChangeSpriteInGameObject()
{
// Getting the Sprite from the Image Component and sign the new one.
spriteRenderer.sprite = new_Sprite;
}