if (closest != null)
{
if (mCenteredObject != null)
{
// Overshoot protection
int startingIndex = GameObjectUtils.GetChildIndex(trans, mCenteredObject.transform);
if (Mathf.Abs(closestIndex - startingIndex) > 1)
{
int clampedIndex = Mathf.Clamp(closestIndex - startingIndex, -1, 1);
int validIndex = Mathf.Clamp(startingIndex + clampedIndex, 0, trans.childCount - 1);
closest = trans.GetChild(validIndex);
}
}
mCenteredObject = closest.gameObject;