I noticed that in a scrollView with children that are not active, the code below doesn't take that into account and returns the incorrect item. I added the following line and it seems to work. Perhaps you can see a better to fix this problem.
for (int i = 0, imax = trans.childCount; i < imax; ++i)
{
Transform t = trans.GetChild(i);
if(!t.gameObject.activeSelf) continue; //Added this line.
float sqrDist = Vector3.SqrMagnitude(t.position - pickingPoint);
if (sqrDist < min)
{
min = sqrDist;
closest = t;
index = i;
}
}