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 GiveBoostIfMovingOnXorYAxis()
     {
         if (Mathf.Abs(GetComponent().velocity.x - 0.2f) <= 0.2f)
         {
             //left or right?
             bool right = Random.Range(-1.0f, 1.0f) >= 0;
             GetComponent().AddForce(new Vector2(right ? 5.0f : -5.0f, 0), ForceMode2D.Impulse);
         }

         if (Mathf.Abs(GetComponent().velocity.y - 0.2f) <= 0.2f)
         {
             //up or down?
             bool down = Random.Range(-1.0f, 1.0f) >= 0;
             GetComponent().AddForce(new Vector2(0, down ? 5.0f : -5.0f), ForceMode2D.Impulse);
         }
     }