how to change sprite sheet in unity at runtime code example
Example: set sprite unity
public Sprite sprite1;
public Sprite sprite2;
private SpriteRenderer spriteRenderer;
void Start ()
{
spriteRenderer = GetComponent<SpriteRenderer>();
if (spriteRenderer.sprite == null)
spriteRenderer.sprite = sprite1;
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.Space))
{
ChangeTheDamnSprite ();
}
}
void ChangeTheDamnSprite ()
{
if (spriteRenderer.sprite == sprite1)
{
spriteRenderer.sprite = sprite2;
}
else
{
spriteRenderer.sprite = sprite1;
}
}