Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to animate two or more unrelated properties on a sprite GameObject using animation layers?

Discussion in 'Animation' started by JesseSTG, Feb 4, 2020.

  1. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    I have a sprite. It is animated like so (with provided mockups):
    • Its base animation is just one frame; i.e. it has the same sprite whether idle or moving.
    • When the player is invincible, the ship flashes in and out. This is implemented by setting the alpha to 0 and 1 and back.
    • The player can acquire up to three levels of shields. The is implemented as a child GameObject with its own Sprite (but not its own Animator).
    • When a player acquires a power-up, they briefly flash colors. This can happen while they're shielded, invincible, or both. This is implemented with a custom palette-swap shader, not by replacing the Sprite.
    These animations are all independent of one another, and can all occur at any time. For example, when a shielded player takes a hit their shield downgrades but they also gain brief invincibility. It would look like this:

    A single state machine to account for these possibilities (and others, depending on whether or not I add other power-ups or mechanics) would be prohibitively complex. So I'm going with animation layers.

    I was hoping that it would be as simple as adding separate animation layers with their own state machines, then marking each layer as additive. Nope. I have no idea what I'm doing.

    How can I use Mecanim to animate my sprite as I have previously described?
     
    Last edited: Feb 4, 2020