set image to sprite code example
Example 1: change sprite of gameobject unity
gameObjectName.GetComponent<SpriteRenderer>().sprite = spriteName;
Example 2: image.sprite unity
Image1.sprite =new Sprite;
gameObjectName.GetComponent<SpriteRenderer>().sprite = spriteName;
Image1.sprite =new Sprite;