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.g - colorDelta,
            spriteRenderer.color.b - colorDelta);

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

        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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.