Using methods in a script

There are two reasons for using methods in a script:

  • To provide behavior to a GameObject
  • To create reusable sections of code

Note

All of the executable code in a script is in methods.

The first purpose of a method is to work with the member variables of the class. The member variables store data that's needed for a Component to give a GameObject its behavior. The whole reason for writing a script is to make a GameObject do something interesting. A method is the place we make the behavior come to life.

The second purpose of a method is to create code blocks that will be used over and over again. You don't want to be writing the same code over and over. Instead, you place the code into a code block and give it a name so you can call it when needed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.204.5