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 OnEnable()
     {
         if( this.photonView != null && !this.photonView.isMine )
         {
             this.enabled = false;
             return;
         }

         if( !cameraTransform && Camera.main )
             cameraTransform = Camera.main.transform;
         if( !cameraTransform )
         {
             Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
             enabled = false;
         }

         m_CameraTransformCamera = cameraTransform.GetComponent();


         _target = transform;
         if( _target )
         {
             controller = _target.GetComponent();
         }

         if( controller )
         {
             CharacterController characterController = (CharacterController)_target.GetComponent();
             centerOffset = characterController.bounds.center - _target.position;
             headOffset = centerOffset;
             headOffset.y = characterController.bounds.max.y - _target.position.y;
         }
         else
             Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );


         Cut( _target, centerOffset );
     }