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(isReadyToShoot){
    fireRate = Random.Range(4, 6);
    firstDelay += Time.deltaTime;
    if (firstDelay >= fireRate) {
     if (!fireBullet) {
      fireBullet = true;
      if (GameObject.FindGameObjectWithTag ("Player") != null) {
       GameObject newBullet = Instantiate (bullet, new Vector3 (transform.position.x, 0.3f, transform.position.z), Quaternion.identity) as GameObject;
       Transform target = GameObject.FindGameObjectWithTag ("Player").transform;
       newBullet.GetComponent ().velocity = (target.position - transform.position).normalized * 5f;
      } else {
       GameObject newBullet = Instantiate (bullet, new Vector3 (transform.position.x, 0.3f, transform.position.z), Quaternion.identity) as GameObject;
       newBullet.GetComponent ().velocity = new Vector2 (Random.Range(-1f, 1f), -2f);
      }
     }

     if (fireBullet) {
      secondDelay += Time.deltaTime;
      if (secondDelay >= 0.5f) {
       secondDelay = 0;
       firstDelay = 0;
       if (GameObject.FindGameObjectWithTag ("Player") != null) {
        GameObject newBullet = Instantiate (bullet, new Vector3 (transform.position.x, 0.3f, transform.position.z), Quaternion.identity) as GameObject;
        Transform target = GameObject.FindGameObjectWithTag ("Player").transform;
        newBullet.GetComponent ().velocity = (target.position - transform.position).normalized * 5f;
       } else {
        GameObject newBullet = Instantiate (bullet, new Vector3 (transform.position.x, 0.3f, transform.position.z), Quaternion.identity) as GameObject;
        newBullet.GetComponent ().velocity = new Vector2 (Random.Range(-0.1f, 0.1f), -2f);
       }
       fireBullet = false;
      }
     }
    }

   }


  }