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 FixedUpdate()
     {
         if (!photonView.isMine)
         {
             return;
         }

         if (Input.GetKey(KeyCode.A))
         {
             transform.position += Vector3.left*(this.Speed*Time.deltaTime);
         }

         if (Input.GetKey(KeyCode.D))
         {
             transform.position += Vector3.right*(this.Speed*Time.deltaTime);
         }

         // jumping has a simple "cooldown" time but you could also jump in the air
         if (this.jumpingTime <= 0.0f)
         {
             if (this.body != null || this.body2d != null)
             {
                 // obj has a Rigidbody and can jump (AddForce)
                 if (Input.GetKey(KeyCode.Space))
                 {
                     this.jumpingTime = this.JumpTimeout;

                     Vector2 jump = Vector2.up*this.JumpForce;
                     if (this.body2d != null)
                     {
                         this.body2d.AddForce(jump);
                     }
                     else if (this.body != null)
                     {
                         this.body.AddForce(jump);
                     }
                 }
             }
         }
         else
         {
             this.jumpingTime -= Time.deltaTime;
         }

         // 2d objects can't be moved in 3d "forward"
         if (!this.isSprite)
         {
             if (Input.GetKey(KeyCode.W))
             {
                 transform.position += Vector3.forward*(this.Speed*Time.deltaTime);
             }

             if (Input.GetKey(KeyCode.S))
             {
                 transform.position -= Vector3.forward*(this.Speed*Time.deltaTime);
             }
         }
     }