[JavaScript] Making an image sprite change upon button click?

Hello, I’m new to Unity. I’ve googled many times and can’t seem to find the exact answer.

This is my code so far:

var Player_Character: Sprite;

var Chara1: Sprite;
var Chara2: Sprite;
var Chara3: Sprite;

function ClickThis() {

GetComponent(SpriteRenderer).sprite = Chara2;

}

I wanted to make a “Character Select” scene where when I click on a button, the character image will change. My game is a 2D game by the way.

Attached file is how my Character Select screen looks like. Also follow-up question: how will this character change reflect on all scenes? Thank you very much in advance.!

40503-best.jpg

For second question: you can use a script that use DontDestoyOnLoad function. With this, the same instance of script will always be present in all scene (with same data).

For first question: you may reference current player sprite texture from buttons, on OnClick (Unity - Scripting API: MonoBehaviour.OnMouseUp()), you can change player material texture.