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:

  public void Start () {
         int levelUnlock = Data.getData(Data.KEY_LEVEL + Attr.currentWorld);

         createHeadTexts(Attr.currentWorld);

         float[] lxs = new float[] { -3, -1.5f, 0, 1.5f, 3, -3, -1.5f, 0, 1.5f, 3, -3, -1.5f, 0, 1.5f, 3 };
         float[] lys = new float[] { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1 };
         for (int i = 0; i < 15; i++)
         {
             GameObject levelObject = (GameObject)Instantiate(prefabs);
             levelObject.transform.parent = gameObject.transform;
             levelObject.transform.localPosition = new Vector3(lxs[i], lys[i], -1);
             FontLevel fontLevel = levelObject.GetComponent();
             fontLevel.setBoardLevel(this);

             //fontLevel.setText("" + (i + 1));
             fontLevel.setText(i < levelUnlock ? heads[i] : hs[i]);

             fontLevel.setStar(Data.getData(Data.KEY_STAR + (Attr.currentWorld * 15 + i)), i < levelUnlock);

             if (i < levelUnlock)
             {
                 fontLevel.bgObject.GetComponent().sprite = bgSprites[Attr.currentWorld + 1];

                 if (i == levelUnlock - 1)
                 {
                     levelObject.AddComponent().addAction(new ActionRepeat(ActionRepeat.FOREVER, new ActionSequence(
                         new ActionScaleTo(0.95f, 0.95f, 0.2f, Interpolation.sine),
                         new ActionScaleTo(1, 1, 0.2f, Interpolation.sine)
                         )));

                 }

                 addClickListener(fontLevel.bgObject, i);
             }
             else
                 fontLevel.bgObject.GetComponent().sprite = bgSprites[0];
         }

         gameObject.AddComponent().addAction(new ActionSequence(
             new ActionScaleTo(0, 0, 0),
             new ActionScaleTo(1, 1, 0.5f, Interpolation.swingOut)));
  }