- Home /
Animated Overlay Armor Sprite
I'm making a 2D top-down RPG, and I want the player to be able to equip different pieces of armor which are shown on the on-screen sprite. I've got a weapon system working easily, since that's just a static sprite that moves and rotates with the player (as a child gameobject), but the armor is different because it has to be animated.
My idea was to create "cut outs" of the armor pieces and then overlay them on top of the player as they move (i.e. the corresponding armor animation frame will be overlaid on top of the player), thus avoiding having to do something like create separate player sprites (wearing armor) for every single armor combination possible. The problem is that I can't seem to find any way of effectively doing this that isn't just as long-winded as having all the separate sprites.
The closest I've got is having a bunch of child gameobjects corresponding to each frame of player animation that get activated and de-activated when the player moves, but this seems like another long-winded way of doing it.
tl;dr I want to have something like a child gameobject of the player that animates along with player movement, i.e. not just a static sprite that gets rotated (since it has to "articulate" with the player), but I don't know how to do this. I'm fairly new to Unity so I wondered if I was missing something really obvious.
Answer by CodeElemental · Jul 20, 2016 at 02:20 PM
You can create a sheet with all the armor cutouts.
Create a child SpriteRenderer called ArmorSprite or w/e. Set it's Order in Scene to be rendered in front of rest of the player.
In the animations editor, try animating the ArmorSprite .sprite property to the appropriate ones.
You can later use the same SpriteRenderer for skinning (i.e. different armor overlays instead).
Ok, now I feel stupid. This exactly what I was looking for, but I was confused for so long since I couldn't see any "+" button to add the property to the animator. Only now do I realize that I wasn't fully scrolled along in the menu, and so the "+" button was hidden.
$$anonymous$$y only other question is: That will work for 1 piece of armor, but what about other pieces? Is it just a matter of enabling/disabling them depending on whether they're equipped? EDIT: Yes it is, I'm simply turning the sprite renderers on or off depending on what the player has equipped - don't know if this is the ideal way of doing it but at least it works for now. Thanks for your help!
Asu$$anonymous$$g you have 2 armors (for ex. leather and metal). You also have their visuals grouped in a sprite sheet (Texture), called by their animations name (idle_1 , idle_2 etc..) the names of the sprites are the same for all sheets. (ex. leather.jpg has sprite names jump_1 jump_2, also metal.jpg) You can override the sprite you render by setting it manually in LateUpdate()
You can create a script that gets the sprites in the specified sheet (via Resources.Load ) in Start(). Create a private dictionary holding them ($$anonymous$$ey = leather , List sprites, etc..)
You can export a Skin property that corresponds to which key to use.
You switch the sprite with the provided skin in LateUpdate()
string skin;
if (skin != null) { Sprite newSprite = _dictionary.[key].Find(sp => sp.name.Equals(spriteRenderer.sprite.name)); spriteRenderer.sprite = newSprite; }
Your answer
Follow this Question
Related Questions
Setting animator parameter on a single instance of a prefab sets the parameter for all instances 3 Answers
Sprites: Project Sprite to Mesh, allow for bending of sprites for 3d environments 0 Answers
Using same animation with different sprite sheets 0 Answers
Sprite Rect Moves Between Frames 0 Answers
Extra frame in simple animations? 0 Answers