Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Nephtis · Jul 20, 2016 at 02:16 PM · animation2dsprite

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by CodeElemental · Jul 20, 2016 at 02:20 PM

  1. You can create a sheet with all the armor cutouts.

  2. 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.

  3. In the animations editor, try animating the ArmorSprite .sprite property to the appropriate ones.

  4. You can later use the same SpriteRenderer for skinning (i.e. different armor overlays instead).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nephtis · Jul 20, 2016 at 04:47 PM 0
Share

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!

avatar image CodeElemental Nephtis · Jul 21, 2016 at 07:35 AM 0
Share

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()

  1. 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..)

  2. You can export a Skin property that corresponds to which key to use.

  3. 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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges