How to create a Character - Unity-Technologies/EndlessRunnerSampleGame GitHub Wiki
Themes being asset bundles, please have a look at the Asset Bundles page first.
Adding a new Character
We can use the characters in Bundles/Characters
as a reference.
We start by creating our character as we would normally: a skinned mesh with an animator (see the default one in Animation/Animators/CharacterAnimation
for the parameters and how they are used. Another possibilities is to copy this one and replace the animation clip in each state)
Note that our characters have all their accessories already part of the mesh as sub object so we can enable/disable them according to which one is equipped. This make it easier to handle but also require all characters to have their own version of each accessories, even if one could be shared amongst characters
Once the animations set up, We add a Character
script to that GameObject
Character properties
We can now fill all the properties required by the Character script on our prefab.
- Character Name, cost and premium cost are self-explanatory
- Accessories is a list of the child objects being the accessories: they will be enabled/disabled by the game depending on which one is equipped. Each need to have a
CharacterAccessories
script on it - Animator is a reference to the animator on our character
- Icon is the icon used in the shop
- We add reference to the sound clip that the character will use when jumping, being hit and loosing the game.
Creating the prefab
We can now prefab your GameObject somewhere in our project (Bundles/Characters/YourCharacterName is recommended to keep thing tidy and coherent). Call the prefab character (naming is important or the asset bundles manager won't find it, see the 2 existing one).
We can now add it to a new asset bundle: at the button of the inspector of the prefab, in the AssetBundle dropdown, we choose New...
and name it character/YourCharacterName
note it is important for the bundle name to start by character/ otherwise the bundle manager won't recognize it as a character
If everything was done properly, clicking on that same AssetBundle drop down should now have a new entry with your character name in the character sub menu
That's the only thing we need to make part of the bundle, as the assetbundle manager will pull in dependency itself. Now our new Character should appear in the shop