I have a problem with my this code and I am not understanding what is wrong:
private static IEnumerator routineDelay(MonoBehaviour mono, List<Transform> objects, float delay, Vector3 target, float speed)
{
for (int i= 0; i < objects.Count;i++)
{
Vector3 n;
n += objects[i].localPosition;
mono.StartCoroutine(routineSmooth(objects[i], n, speed));
yield return new WaitForSeconds(delay);
}
}
private static IEnumerator routineSmooth(Transform objToDamp, Vector3 target, float speed)
{
velocity = new Vector3();
while (!exit)
{
objToDamp.transform.position = Vector3.SmoothDamp(objToDamp.transform.position, target, ref velocity, 1, 20, speed * Time.deltaTime);
yield return null;
}
}
What is happens is that sounds like one routine is influencing in the others. Like some variable is referenced and not actually run as unique in each routine.
But I am creating the parameters like Velocity to a new each time to avoid it.
The idea is very simple. Just move objects to another position but with a delay between them so the animation look better.
If we call just one routine works fine.
Look, this is called just once Twinning.doDampingChilds(this, objList, target, speed, delay);
This “objList” have childrens that we wll pass each in “routineSmooth”