Game Development Reference
In-Depth Information
1.5.2 Comments
Comments aren't actually programming code. They are, however, inserted
lines of freeform text totally ignored by the compiler. They allow you
to insert explanations about your code or little reminders to what your
code does. They are very useful when you write some ground-breaking
code, leave it for 6 months, and then come back to it, having forgotten what
it does. The author's advice is to use comments as frequently as possible.
It is common practice to place comments at the top of each program file
to give an overview of the entire code, as well as above each function.
Another programmer may also insert comments if he makes a change.
Some examples are shown in Listing 1.7 .
Listing 1.7 A Short Program with Comments
/*Program: spin.js
Description:
Will rotate any game object around the y axis
Author:
Penny de Byl
Date:
12/08/2010
*/
function Update()
{
//rotate around the vertical axis with a speed of 10
transform.Rotate(Vector3.up * 10);
}
There are two types of comments. The first is a way to block out an entire
paragraph. It begins with a /* and ends with a */. You can write anything
you want between these characters and it will be totally ignored by the
compiler. The second type is a one liner. A line starting with // will also be
ignored by the compiler, but only until the end of the line. Therefore, you
could write this:
/* Here are some comments about my program I wrote
to control a spinning cube in Unity. I used the code I
found in the Script Reference after doing a search for the
word Rotate.*/
or this:
//Here are some comments about my program I wrote to
control a
//spinning cube in Unity. I used the code I found in the
//Script Reference after doing a search for the
word Rotate.
 
Search Nedrilad ::




Custom Search