How to change sprite using a button?

I’m trying to make a little in game store with skins for my player.
I’ve set up my store it has a bunch of buttons. But i don’t know how to write a function for them that makes the sprite on my player change into another sprite. I tried to search for some tutorials on this but i can’t find any that work. Thank you if you help me with this issue.

Ok, heres how I would do it. Make a new C# script on the object that you want to change the sprite on. In this case I have named it ‘ChangeSprite’

using UnityEngine;
using System.Collections;

public class ChangeSprite : MonoBehaviour {

	SpriteRenderer spriteRenderer; //will store sprite renderer

	void Start()
		spriteRenderer = gameObject.GetComponent<SpriteRenderer> (); //get sprite renderer & store it

	public void change(Sprite differentSprite)
		spriteRenderer.sprite = differentSprite; //sets sprite renderers sprite

The gist is that we have created a variable to store our sprite renderer (the component that displays sprites in game) We have set that to the sprite renderer attached to this object. Then we have made a function that takes a sprite as input which is used to set the sprite of the sprite renderer.

Anywho go to your button object. There will be an on click section near the bottom. Set the object on the left to the object whose sprite you are changing and set the dropdown on the right to ChangeSprite > change

Now set the sprite you want to change it to below. This is individual for each button so you can use different buttons to set differnt sprites (thumbnails maybe)

hope this helps :slight_smile: if you need any more info let me know.