So, I want to set the alpha on all the child widgets of a given panel, and when the alpha reaches zero, then deactivate each widget. I'm using the following code:
UIWidget[] widgets = panel.GetComponentsInChildren<UIWidget>();
Debug.Log("found " + widgets.Length + " widgets!");
foreach (UIWidget w in widgets)
{
Debug.Log("Setting alpha tween on " + w.name);
TweenAlpha
.Begin(w
.gameObject,duration,0
.0f
).onFinished.Add(new EventDelegate
(delegate(){ Debug.Log("want to disable: " + w.name);
NGUITools.SetActive(w.gameObject,false);
}));
}
The Debug.Logs will illustrate the problem. When I'm iterating over the list, w is set to each object and the 'setting alpha' debug log displays the correct object, however once the alpha fades out, the 'disable' debug log always shows the last item in the list for each alpha.onFinished.
So, either I need some way to have the w value used in the delegate to reference the value in the loop when it's created, or is there someway inside the delegate to get the object it's being run on?