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 Update () {
   if(transform.position.x < generatePoint.position.x) {

    distance = Random.Range (distanceBetweenMin, distanceBetweenMax);

    groundSelector = Random.Range (0, theObjectPools.Length);

    heightChange = transform.position.y + Random.Range (maxHeightChange, -maxHeightChange);

    if (heightChange > maxHeight) {
     heightChange = maxHeight;
    } else if (heightChange < minHeight) {
     heightChange = minHeight;
    }

    transform.position = new Vector3 (transform.position.x + (groundWidth[groundSelector] / 2) + distance, heightChange, transform.position.z);

    GameObject newPlatform = theObjectPools[groundSelector].GetPooledObject ();
    newPlatform.transform.position = transform.position;
    newPlatform.transform.rotation = transform.rotation;
    newPlatform.SetActive (true);

    if(Random.Range(0f, 100f) < randomCoins) {
     coinGenerator.spawnCoins (new Vector3 (transform.position.x, transform.position.y + 3f, transform.position.z));
    }

    if(Random.Range(0f, 100f) < randomCrates) {
     cratesGenerator.spawnCrates (new Vector3 (transform.position.x, transform.position.y + 1.3f, transform.position.z));
    }

    transform.position = new Vector3 (transform.position.x + (groundWidth[groundSelector] / 2) + distance, transform.position.y, transform.position.z);

   }
  }