In addition to what Michael wrote: You may name your variables as you wish. The compiler will tell you if a name is invalid. As long as there is nobody to tell you what to do (e.g. your employer’s naming convention), your names are correct/valid by definition if the compiler does not complain.
In this course, we follow one of the most common C# naming conventions, which is also widely used in the Unity community. Names with an underscore are uncommon in C# but you sometimes see names with underscores in the Unity API and elsewhere.
As for me, I prefer to name my instance variable rigidbody
because rb
is fairly meaningless in my opinion. If the code is more complex, I would not want to guess around what rb
might be, especially not there are more names such as as
, bc
, t
, a
, b
and so on. At some point, the code might become hard to read.
However, sometimes, I’m lazy and name local Rigidbody variables rb
. Depending on the complexity of the code, rb
might be sufficient. Many people name their Rigidbody variables rb
.
For experienced Unity programmers (like your future self), c_
or comp_
do not add any relevant information to the name because, in the context of Unity, Rigidbody is always used as a component. Furthermore, you would have to ask yourself: Why do I need to know that this Rigidbody is a component? Is this information relevant for what I’m doing here in the code?
In the end, it’s a matter of personal preference, though. Make your code as readable as possible, so your future self won’t have to guess around but also will not get bored/confused by irrelevant information.
See also: