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 Start (){

   int x;
   int y;
   int z;
   int axis;
   yOffset = 1F;
   Transform blockInstance;
   BlockScript blockScript;
   ConnectorScript connectorScript;
   Transform connectorInstance;
   TextMesh textMesh;

   this.gameView = "menu";
   this.options = this.gameObject.GetComponent ("OptionsScript") as OptionsScript;
   this.timer = this.gameObject.GetComponent ("TimerScript") as TimerScript;
   this.sizeGUI();

   this.options.InitOptions();

   //setup audio sources

   AudioSource[] audioSources = GetComponents();
   this.swipeAudioSource = audioSources[0];
   this.collideAudioSource = audioSources[1];
   this.collideAudioSource.clip = this.collideSound;

   //instantiate the blocks and connectors and position them
   for (x = 0; x <= 2; x++) {
    for (y = 0; y <= 2; y++) {
     for (z = 0; z <= 2; z++) {
      //instantiate the block
      blockInstance = Instantiate (block, new Vector3(x * this.scale, y * this.scale + this.yOffset, z * this.scale), Quaternion.identity) as Transform;
      this.blocks[x,y,z] = blockInstance;
      blockScript = blockInstance.gameObject.GetComponent("BlockScript") as BlockScript;
      blockScript.Initialize(x,y,z,this);
     }
    }
   }

   // instantiate the connectors
   for (x = 0; x <= 2; x++) {
    for (y = 0; y <= 2; y++) {
     for (z = 0; z <= 2; z++) {
      //instantiate the x connector
      connectorInstance = Instantiate (connector) as Transform;
      connectorScript = connectorInstance.gameObject.GetComponent("ConnectorScript") as ConnectorScript;
      connectorScript.Initialize(x,y,z,"x", this);
      this.connectors[x,y,z,0] = connectorInstance;

      //instantiate the y connector
      connectorInstance = Instantiate (connector) as Transform;
      connectorScript = connectorInstance.gameObject.GetComponent("ConnectorScript") as ConnectorScript;
      connectorScript.Initialize(x,y,z,"y", this);
      this.connectors[x,y,z,1] = connectorInstance;

      //instantiate the z connector
      connectorInstance = Instantiate (connector) as Transform;
      connectorScript = connectorInstance.gameObject.GetComponent("ConnectorScript") as ConnectorScript;
      connectorScript.Initialize(x,y,z,"z", this);
      this.connectors[x,y,z,2] = connectorInstance;
     }
    }
   }

   //instantiate the move blocks
   if (PlayerPrefs.HasKey ("game_status")) {
    this.loadSavedGame();
   }
   else {
    this.restart ();
   }
  }