For inside a courutine inst working properly
Well this is a code when the courutine recieves 2 ints representing an x and y values wich the unit should move. For example, recieving x2 and y3 means unit should move right twice and up three times (unit moves tile per tile);
Im using a courutine so i can have a smooth animation of my char to move from his source to the next tile, till x and y reaches 0. This is my code, but the problem is that the for inside the courutine isnt working properly and is not doing it "smooth".
IEnumerator Move1(Transform object, int mueveenX, int mueveenY)
{
for (int mY = mueveenY; mY > 0; mY--)
{
object.transform.position = Vector3.Lerp(object.transform.position, object.transform.position+ new Vector3(0,mueveenY), 2f * Time.deltaTime);
yield return null;
}
for (int mX = mueveenX; mX > 0; mX--)
{
object.transform.position = Vector3.Lerp(object.transform.position, object.transform.position + new Vector3(0, mueveenX), 2f * Time.deltaTime);
yield return null;
}
yield return null;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612080857im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to move an object left and right by dragging mouse after clicking left mouse button. 0 Answers
How do I make text move up? 1 Answer
Player looses ability to jump further right player moves. 1 Answer
I want to create an object that only moves if i click in others 4 objects that i have in the scene 0 Answers
apply force in camera direction 0 Answers