- Home /
Generic 2D Animators
I'd like to create a 2D generic Animator component for all enemies and that has animations mapped to specific areas of a sprite sheet. Then for each enemy sub-type, I could set the sprite sheet asset via scripting and the animator would display the sprite tiles for that sheet.
Is this possible?
Answer by PeterKramer · Jul 28, 2014 at 12:08 AM
Sorry for the incredibly late response, but I was planning on doing the same and have now found a possible workaround - you've probably resolved your issue by now.
However, what you can do is use Animation Events to call a method on a custom script with a numeric value as parameter that corresponds to the ID of the sprite.
The script would need to have the name of the sprite sheet stored and build the sprite name from those two components as "[sheet name]_[id]".
The corresponding sprite could then be requested from another script which simply contains an array (or a dictionary with name->sprite mapping) of all sprites available and a method for lookup by name.
Once the Sprite has been retrieved, simply update the SpriteRenderer to use the given sprite.
This may be a bit complex and/or possibly unoptimized, but it'll work.