Question by
Crimx · Jan 15, 2016 at 05:33 PM ·
animationscripting problem
Moving Forward and Backward continously using IENumerator
Hi, I want to make my object move up and down with IENumerator. I'm using this code and my object can move up.
IEnumerator floatingAround()
{
while (isFloat)
{
this.transform.position = Vector2.Lerp(this.transform.position, topPosition, Time.deltaTime * speed);
distance = Vector2.Distance((Vector2)this.transform.position, topPosition);
yield return new WaitForEndOfFrame();
}
So, I modified it a bit to make my object move down when my object reaches max height, and become like this
IEnumerator floatingAround()
{
Vector2 temp;
while (isFloat)
{
if (trigger) temp = topPosition;
else temp = bottomPosition;
this.transform.position = Vector2.Lerp(this.transform.position, temp, Time.deltaTime * speed);
distance = Vector2.Distance((Vector2)this.transform.position, temp);
yield return new WaitForEndOfFrame();
}
yield return new WaitForEndOfFrame();
}
but this code won't make my object go down, and its happen too when I try to make my object goes down first. Any suggestion for this code?
Comment
Your answer
