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:

         private void createGrounds(Transform parentTransform, Transform markGounds)
         {
             for (int i = 0; i < parentTransform.childCount; i++)
             {
                 GameObject groundObject = parentTransform.GetChild(i).gameObject;
                 groundObject.name = "GroundObject";
                 Rigidbody2D groundBody = groundObject.AddComponent();
                 groundBody.isKinematic = true;
                 groundBody.gravityScale = 0;

                 BoxCollider2D groundCollider = groundObject.GetComponent();

                 //them 1 cai gameobject chua boxcollider ngay truoc cac khoi dat
                 float height = groundObject.GetComponent().size.y;
                 GameObject markObject = new GameObject("MarkGround");
                 markObject.transform.parent = markGounds;
                 markObject.transform.localPosition = groundObject.transform.localPosition;
                 BoxCollider2D markCollider = markObject.AddComponent();
                 markCollider.size = new Vector2(0.1f, (height - 4)/100);
                 markCollider.offset = new Vector2(0, - height / 200);
             }
         }