So I have this coroutine that moves an object to a place, and I do it for a list of objects, but I want it to move them one by one (aka wait until previous coroutine is done before starting a new one) but adding any yields just stops the whole thing... im a bit lost to why.
Ive tried adding "yield return new WaitUnitl()" or "WaitForSeconds" but wherever i try to place it it either makes it wait before moving everything at once or they just stop moving all at once
Moving code:
public IEnumerator MoveObject(Vector3 source, Vector3 target, float overTime)
{
float startTime = Time.time;
while (Time.time < startTime + overTime)
{
transform.position = Vector3.Lerp(source, target, (Time.time - startTime) / overTime);
yield return null;
}
transform.position = target;
}
called in this for loop:
for (int i = 0; i < CardsInHand.Count; i++)
{
Card c = CardsInHand[i];
Vector3 target = new Vector3(startt + (1.5f * i), transform.position.y);
StartCoroutine(c.MoveObject(c.transform.position, target, 1));
c.GetComponent<SpriteRenderer>().sortingOrder = i;
}
Expect them to move one at a time, not all at once
Edit: well I had the biggest fart ever.... i forgot to use StartCoroutine() after making the method a coroutine... and i kept wondering why it wont move