how to change the sprite of a UI image in code unity code example
Example: unity ui change sprite
// TO change the sprite of an UI image, se below
GameObject.GetComponent<Image>().sprite = sprite;
// TO change the sprite of an UI image, se below
GameObject.GetComponent<Image>().sprite = sprite;