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:

   protected override void OnCantMove (T component)
   {
    //Declare hitPlayer and set it to equal the encountered component.
    Player hitPlayer = component as Player;

    //Call the LoseFood function of hitPlayer passing it playerDamage, the amount of foodpoints to be subtracted.
    hitPlayer.LoseFood (playerDamage);

    //Set the attack trigger of animator to trigger Enemy attack animation.
    animator.SetTrigger ("enemyAttack");

    //Call the RandomizeSfx function of SoundManager passing in the two audio clips to choose randomly between.
    SoundManager.instance.RandomizeSfx (attackSound1, attackSound2);
   }