void OnBallAdded(int index, Ball b, Ball targetBall, float progress) { index = balls.IndexOf(targetBall); //Debug.Log(index); if (index < 0 || index > balls.Count - 1) { return; } lockMove = true; float percentProgress = 0; //closeer to finish Vector3 positionLeft = Path.GetArcParametrizedTime(targetBall.Progress + 2 * BallSizePercent, ref percentProgress); //closeer to start Vector3 positionRight = Path.GetArcParametrizedTime(targetBall.Progress - 2 * BallSizePercent, ref percentProgress); Vector3 contactPoint = b.transform.position; float dtFinish = Vector3.Distance(positionLeft, contactPoint); float dtStart = Vector3.Distance(positionRight, contactPoint); int newIndex = index; if (dtFinish < dtStart) { newIndex = index; } else { newIndex = index + 1; } balls.Insert(newIndex, b); b.Progress = targetBall.Progress; b.transform.position = targetBall.transform.position; targetBall.CopyState(b); shiftBalls(index); if (!checkDestroyAfterbackwards(index, b)) { bool destroyed = getDestroyable(newIndex, false); if (!destroyed) { EffectsPlayer.SpheresCollided(); } } lockMove = false; }