- Import your sprite sheet into Unity
- Click on your imported sprite sheet
- Look at the 'Inspector' tab
- Set 'Sprite Mode' to Multiple
- Then open up 'Sprite Editor'
- Click 'Slice'>'Grid by Cell Size' and enter appropriate "Pixel Size" x and y values
- IMPORTANT STEP: Click on 'Sprite Editor' tab, this will open up a dropdown menu with 4 options. Choose option "Custom Outline"
- In "Sprite Editor">"Custome Outline", click on the first sprite, then click "Generate" at the top which will generate a shape with several points around the sprite. Remove all but 4 points. Make a box shape that matches the Cell Size. Then, with the first sprite still selected, click on 'Copy' at the top and finally click "Paste All".
- Repeat 1-8 for all sprite sheets you imported
- Open a new scene
- Create an empty game object & name it Player
- Add the Sprite Renderer component
- Add the Animator component
- Create your animation clips by selecting sprites from the players main spritesheet and drag them onto the player
- This will create an AnimatorController, name it "PlayerAnimatorController"
- In the Player>Animator component, set the Controller to "PlayerAnimatorController"
- This will also create an AnimationClip, name it whatever you want
- Setup your animations in the Animator tab in unity
- At the top of Unity, click "Assets">"Create">"Material"
- Name this Material PlayerMaterial.mat
- Click on the Material and go to Inspector
- Click on "Shader" dropdown menu, choose "Unlit">"PlayerShader"
- Set the Current SpriteSheet to your players main sprite sheet for now
- Drag PlayerMaterial.mat onto your player game object
- Click on the Player gameobject in your scene
- In the Inspector, scroll down to the PlayerMaterial tab and click on the dropdown arrow
- Set the Current SpriteSheet texture to your players main spritesheet
- Now, add ManageSprite.cs to the Player gameobject
- Click on Player gameobject
- In the Inspector, inside the ManageSprite (Script) component, add your characters main spritesheet to the PlayerSpriteSheets list.
- Add as many alternate character spritesheets to this list!
- Now edit ManageSprite.cs Update() code to change your characters current spritesheet to any spritesheets from your PlayerSpriteSheets list! This will let you change your characters appearance in game without having to create new animation clips, thus allowing you to reuse your players main animation clips!
I am no shader expert. I basically looked at the unity docs, figured out how to make an unlit shader and then parsed their unlit/transparent shader to figure out how to make the texture transparent. Seems to be working just fine so far, but please report any bugs.