-1
\$\begingroup\$

Im trying to lerp the scale of a game objecto to 30% its size and then back again, but all i get as output is "

Blippping Cursor

up scale 0

down scale 0

        IEnumerator Blip_cr (Vector2 position)
    {
            coordinateSelected = true;
            SetPosition (position);

            print ("Blippping Cursor");
            var duration = 10f;
            var startScale = transform.localScale;
            var targetScale = startScale * 1.3f;
            var startTime = Time.time;
            var progress = 0f;

            while (progress < 1) {
                    print ("up scale " + progress);
                    var newScale = Vector3.Lerp (startScale, targetScale, progress);
                    progress = duration / (Time.time - startTime);
                    transform.localScale = newScale;
                    yield return  null;
            }
            progress = 0;
            startTime = Time.time;
            while (progress < 1) {
                    print ("down scale " + progress);
                    var newScale = Vector3.Lerp (targetScale, startScale, progress);
                    progress = duration / (Time.time - startTime);
                    transform.localScale = newScale;
                    yield return  null;
            }

            coordinateSelected = false;
    }
\$\endgroup\$
  • 1
    \$\begingroup\$ You forgot to tell us what the problem is and what you've tried already. This looks like it's just a debugging problem. Tell us what debugging steps you've already taken. \$\endgroup\$ – MichaelHouse Feb 7 '14 at 4:46
  • 2
    \$\begingroup\$ This question appears to be off-topic because it is about debugging your code for you. \$\endgroup\$ – Anko Feb 7 '14 at 13:46
1
\$\begingroup\$

The formula for progress looks wrong. I think it should be:

progress = (Time.time - startTime) / duration;
\$\endgroup\$
  • \$\begingroup\$ Ahhh! Thanks! Im quite new at this. I will keep that in mind. :) \$\endgroup\$ – Daarwin Feb 7 '14 at 13:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.