Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

         void CalculateRadial()
         {
             m_Tracker.Clear();
             if (transform.childCount == 0)
                 return;
             float fOffsetAngle = ((MaxAngle - MinAngle)) / (transform.childCount);

             float fAngle = StartAngle;
             for (int i = 0; i < transform.childCount; i++)
             {
                 RectTransform child = (RectTransform)transform.GetChild(i);
                 if (child != null)
                 {
                     //Adding the elements to the tracker stops the user from modifiying their positions via the editor.
                     m_Tracker.Add(this, child,
                     DrivenTransformProperties.Anchors |
                     DrivenTransformProperties.AnchoredPosition |
                     DrivenTransformProperties.Pivot);
                     Vector3 vPos = new Vector3(Mathf.Cos(fAngle * Mathf.Deg2Rad), Mathf.Sin(fAngle * Mathf.Deg2Rad), 0);
                     child.localPosition = vPos * fDistance;
                     //Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points.
                     child.anchorMin = child.anchorMax = child.pivot = new Vector2(0.5f, 0.5f);
                     fAngle += fOffsetAngle;
                 }
             }

         }