Demigiant Forum
Unity Assets => DOTween & DOTween Pro => Topic started by: shawhu on March 22, 2016, 09:24:23 AM
-
List<GameObject> mylist=GetMyList();
foreach(var item in mylist){
item.transform.DOMove (position, 2, false).OnComplete(()=>{Destroy(item.gameobject);})
}
This doesn't work. When items complete one by one, they will always delete the last item in the list.
-
Hi,
This is sadly a Unity bug with foreach (http://dotween.demigiant.com/support.php?faq=Tweens%20and%20callback%20targets%20inside%20foreach) (should be fixed when they update to a newer NET version).
Just reassign your item inside the loop and it will work:
foreach(var item in mylist){
var it = item;
it.transform.DOMove (position, 2, false).OnComplete(()=>{Destroy(it.gameobject);})
}
Cheers,
Daniele