gameObjectName.GetComponent<SpriteRenderer>().sprite = spriteName;
// TO change the sprite of an UI image, se below
GameObject.GetComponent<Image>().sprite = sprite;
public SpriteRenderer spriteRenderer;
public Sprite newSprite;
void ChangeSprite()
{
spriteRenderer.sprite = newSprite;
}
public SpriteRenderer spriteRenderer;
public Sprite newSprite;
void ChangeSprite()
{
spriteRenderer.sprite = newSprite;
}Copied!