Search Unity

I've been left in the lerp!

Discussion in 'Scripting' started by San_Holo, Nov 29, 2014.

  1. San_Holo

    San_Holo

    Joined:
    Sep 26, 2014
    Posts:
    152
    I'll post my code below, please explain how you fixed it :)

    I've got a sprite and I'm getting it's local scale of whatever it's set to and then over time scaling it down with lerp to a new vector 3 zero and it's working, but here it just happens the once or my timing if off and I can't see it, can you help? cheers

    see next post
     
    Last edited: Nov 29, 2014
  2. San_Holo

    San_Holo

    Joined:
    Sep 26, 2014
    Posts:
    152
    Got it, I was trying to take too many short-cuts perhaps... anyway
    Code (csharp):
    1.         public IEnumerator SpriteScaleOut ()
    2.         {
    3.                 _interpolator = 0.0f;
    4.                 while (_interpolator < 2.0f) {
    5.                         _interpolator += Time.deltaTime * 0.02f;
    6.                         transform.localScale = Vector3.Lerp (transform.localScale, _current, _interpolator);
    7.                         yield return null;
    8.                 }
    9.                
    10.         }
    Code (csharp):
    1. private Vector3 _current = Vector3.zero;
    2.         private float _interpolator = 0.0f;
    Does the trick for me...