Пример #1
0
        private void Generate()
        {
            UOUtility.DestroyChildren(Generated);
            wayPoints.Clear();

            float localSpacing = 0;
            Joint joint        = null;

            for (int i = 0; i < segmentCount; i++)
            {
                var seg = UOUtility.Instantiate(segmentPrefab, Generated.transform);
                seg.transform.Translate(0, 0, localSpacing);

                var segRB = seg.GetComponent <Rigidbody>();
                // we fix the first segment so that the rope won't fall
                if (i == 0)
                {
                    firstSegment      = seg;
                    segRB.constraints = RigidbodyConstraints.FreezePosition;
                }

                // we attach the rigidbody to the joint of the previous segment
                if (joint != null)
                {
                    joint.connectedBody = segRB;
                }
                joint = seg.GetComponent <Joint>();

                // we save segments as way points for the spline deformation.
                wayPoints.Add(seg);
                localSpacing += segmentSpacing;
            }
            UOUtility.Destroy(joint);
        }