I created a menu command to clone a selected base character object into 4 color variants, changing the name, script parameters and animation sprites of each variant accordingly. A prefab is created for each variant, with the color name appended.
For instance, a game object named
Character_Blue will be cloned into 3 prefabs
Character_Green. Their character data will point to the corresponding colors and player numbers, and their sprite animations will match their colors.
The script execution is done is 3 steps:
- Get resource spritesheets for each variant. Each spritesheet is imported as a Unity Multiple Sprite asset where each sprite is rigorously named, e.g.
- For each variant, create copies of the animations of the base character, replacing each sprite reference at each key frame with the corresponding variant, e.g. on frame 1 of animation Walk Down of the Red variant, replace
- For each variant, create an Animator Override Controller that replaces each animation reference with the corresponding variant animation created in the previous step.
I wrote the script because each time I was modifying one of the game characters, I wanted to propagate the changes on other characters. Since they were all using the same scripts but differed by their color and player number, I decided to create a command to generate 3 variants from one.