From the course: Unity 5: 2D Emulate Palette Swapping for Sprites

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Cloning a texture

Cloning a texture

- So now that we're able to save the values of our color palette, let's look into building out a new class that'll let us swap out those colors on a sprite renderer. Inside of our scripts folder, we're going to create a new C# script called palette swapper. Let's open this up in MonoDevelop. Now, we're going to apply this class to a game object, so we'll leave it extending mono behavior. And we're going to need two properties to get started. The first one's going to be a public property typed to sprite renderer, and we'll call this sprite renderer. Next, we'll need an array to contain the palettes. We're going to be a little forward-thinking here, instead of just adding one new palette to this class, we're going to allow us to have multiple palettes attached, and we'll randomly pick a palette. So this way, if you wanted to have a kind of variety in your game, you can add a whole bunch of different palettes, and the palette swapper will take care of this for you. Here we'll create a…

Contents