change sprite unity c# code example
Example 1: change sprite of gameobject unity
gameObjectName.GetComponent<SpriteRenderer>().sprite = spriteName;
Example 2: unity ui change sprite
// TO change the sprite of an UI image, se below
GameObject.GetComponent<Image>().sprite = sprite;