850176300 / dotween

Automatically exported from code.google.com/p/dotween
0 stars 0 forks source link

Some properties are not being updated properly #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Here is my code:
private IEnumerator ShowRippleCoroutine(float delay, Transform targetTransform)
        {

            yield return new WaitForSeconds(delay);
            if(targetTransform != null)
                transform.position = targetTransform.position;

            m_animating = true;
            ResetObjects();

            for (int i = 0; i < RippleSprites.Length; i++)
            {
                UI2DSprite rippleSprite = RippleSprites[i];

                ResetObjects();

                Sequence animSequence = DOTween.Sequence();

                float interval = i*0.45f;
                animSequence.AppendInterval(interval);

                animSequence.Append(
                    DOTween.To(() => rippleSprite.alpha, x => rippleSprite.alpha = x, 1, .35f)
                    );

                animSequence.Append(
                    rippleSprite.cachedTransform.DOScale(Vector3.zero, .9f)
                    .SetEase(Ease.InCirc)
                    );

                animSequence.Play();
            }

            if (m_loop)
            {
                yield return new WaitForSeconds(4f);

                StartCoroutine(ShowRippleCoroutine(0, null));
                yield break;
            }
            m_animating = false;
        }

What is the expected output? What do you see instead?
I'm expecting that the Object FadeIn then Scaledown, instead the alpha property 
are beein updated in only one object. 

What version of the product are you using? On what operating system?
1.0.080

Please provide any additional information below.

Original issue reported on code.google.com by bad...@gmail.com on 11 Feb 2015 at 1:45

GoogleCodeExporter commented 9 years ago
Hi,

I must add this to the FAQ. The problem is due to the tween being created 
inside a FOR loop inside a coroutine (which messes up with lambda references - 
while as you saw shortcuts work instead). Place your tween creation FOR loop 
inside a function and call the function from the coroutine to make it work.

private IEnumerator ShowRippleCoroutine(float delay, Transform targetTransform)
{

    yield return new WaitForSeconds(delay);
    if(targetTransform != null)
       transform.position = targetTransform.position;

    m_animating = true;
    ResetObjects();

    CreateTweens();

    if (m_loop)
    {
       yield return new WaitForSeconds(4f);

       StartCoroutine(ShowRippleCoroutine(0, null));
       yield break;
    }
    m_animating = false;
}

void CreateTweens()
{
   for (int i = 0; i < RippleSprites.Length; i++)
   {
      UI2DSprite rippleSprite = RippleSprites[i];

      ResetObjects();

      Sequence animSequence = DOTween.Sequence();

      float interval = i*0.45f;
      animSequence.AppendInterval(interval);

      animSequence.Append(
         DOTween.To(() => rippleSprite.alpha, x => rippleSprite.alpha = x, 1, .35f));

         animSequence.Append(
            rippleSprite.cachedTransform.DOScale(Vector3.zero, .9f)
                .SetEase(Ease.InCirc)
            );

            animSequence.Play();
   }
}

Original comment by daniele....@gmail.com on 12 Feb 2015 at 8:00