How do I make a change skin button for my game

(c sharp) So, I have a 3d platformer ball game, where I want to implement a “change skin” system where you will be able to click a button to chose texture for the entire game for your player (change texture of a prefab I guess). I don’t know how to make this script but I know that you can change color by doing
Renderer myRender;
myRender.material.color = Color.yellow;
but I don’t know how do i do the same thing but with a texture. Can someone please help me because this is a thing I would like the most in my game. Thank you so much :slight_smile:

You need a Texture2D variable then…
you can use SetTexture(propertyName: string, texture: Texture);
or SetTexture(nameID: int, texture: Texture);

The first propriety can be a string with the name of the texture you wanna change. For example if you’re using a shader with 3 textures… like… a simple texture, a normal map and a Heightmap, you’re gonna need to use “_MainTex” and other names. The easiest way is using integers. For example, if the base texture is the first one, you write the first propriety as 1.
The texture is gonna be your Texture2D variable.
You can have a few textures in your unity project and have a specific var for every one of them or you could use an array. I’m using javascript so i’m not sure how it works in C Sharp, in javascript is:
var Name : Texture2D;

And you can add how many textures you want in the inspector, then you set the texture of the object to Name[int];
For example if you wanna set it to the 4th texture u have to do it like:
SetTexture(1, Name[4]);

Everything should be the same in C Sharp besides the variables.

I looked it up, i think it’s: public Texture2D Name;
So…

public Texture2D[] Name;

void Start () {
 GameObject.FindGameObjectWithTag("tag").SetTexture(1, Name[4]);
}

Good luck :wink:

So Will this work if I make a button in the main menu, and then switch scenes to the actual game? Will the texture stay of reset? Thanks for the help though :slight_smile:
@TheMiningSheep