What goes in [ ] and what does #if mean?


I would like to know what the means like [Serializable] Also I wanna know what # then something else since i’ve seen #if and #end but I don’t know what they mean. If anyone could give me some documentation of these and explain them ill appreciate it.

Both the [] above classes and the # before an if are C# language specific features. The above a class is called an attribute . Unity does have some custom attributes like [HideInInspector]. The # before an if means it is a preprocessor directive it tells the compiler to check those directives before compiling the code. In unity preprocessors are commonly used to write code that is platform dependent which means that you can write code that will only be compiled when building for a specific platform. For example you may want to make a game for both pc and android devices. Both platforms have very different ways of handling input, so you could write a preprocessor for android that contains touch input code and a preprocessor for pc with input code for mouse and keyboard.

Here are the docs:

The first thing is called an attribute. Attributes are special classes which allows you to “attach” meta data to classes or class members such as variables / fields and methods. The Serializable attribute is used by most serializing frameworks. It indicates that this class can be serialized.

In C# anything that starts with # is not actually part of the code but is read by the pre-processor. The pre-processor (as the name suggests) processes the source code before it’s actually compiled