0

I have a GameObject with Animator and looped animation clip.
This animation changes X coordinate from 0 to 10 and back.

I need to add another animation to the first one that increases GameObject's scale and changes its color to red simultaneously.

After scale and color change GameObject keeps these parameters and continues to move according to the first animation clip.

The only way I managed to work it around is writing a custom script with couroutine:

IEnumerator Animate()
{
    float scaleDelta = 0.2f;
    float colorDelta = 0.02f;
    for (int i = 0; i < 50; i++)
    {
        spriteRenderer.color = new Color(
            spriteRenderer.color.r,
            spriteRenderer.color.g - colorDelta,
            spriteRenderer.color.b - colorDelta);

        transform.localScale = new Vector3(
            transform.localScale.x + scaleDelta,
            transform.localScale.y + scaleDelta,
            transform.localScale.z);

        yield return new WaitForSeconds(0.02f);
    }
}

This works for linear interpolation, but requires to write additional code and write even more code for non-linear transformations.

How can I achieve the same result with Mecanim?

Sample project link: https://drive.google.com/file/d/0B8QGeF3SuAgTU0JWNGd2RnpUU00/view?usp=sharing

Skyblade
  • 2,354
  • 4
  • 25
  • 44
  • 1
    I can't look at your sample project at the moment, but have you considered using [Animation Layers](http://docs.unity3d.com/Manual/AnimationLayers.html) for this? You can specify on them that blending should be Additive, which sounds like what you're looking for here. (If that isn't the case, please provide additional details indicating how your requirements differs from it.) – Serlite Feb 10 '16 at 20:40
  • @Serlite Looks like what I need. Thanks, I'll try this. – Skyblade Feb 11 '16 at 06:51
  • Great - let me know if it works out, and I'll add this as an answer so you can mark this question as solved. – Serlite Feb 11 '16 at 15:12
  • @Serlite yes, it actually worked, though I have to keep idle animation running endlessly to keep object prepared for new transformations. Thanks! – Skyblade Feb 14 '16 at 08:11

0 Answers0