As others mentioned, those are attributes. They allow you to provide more data or functionality to classes, methods, properties, fields, etc… Actually, if you make a custom attribute, you’ll see that there isn’t too much magic behind how they behave; here is a small (albeit a bit silly) example of creating a custom attribute and then using it in your own code.
Declare the silly attribute:
public class MyValueAttribute : System.Attribute
{
public int SomeValue = 0;
public MyValueAttribute(int value)
{
this.SomeValue = value;
}
}
To apply it to a class (note you do not need to call it by its full name when used in square brackets, though you can actually do so if you want):
[MyValue(5)]
public class Joystick : MonoBehaviour
{
// ... //
You can employ Reflection to actually make “use” of this silly attribute (using the word “use” loosely):
object[] attributes = typeof(Joystick).GetCustomAttributes(typeof(MyValueAttribute), false);
if (attributes.Length > 0)
{
MyValueAttribute myAttribute = attributes[0] as MyValueAttribute;
System.Diagnostics.Debug.Assert(myAttribute.SomeValue == 5);
}
As you might imagine, you can probably find a more practical way to use attributes, though I find that they are more interesting and applicable when designing frameworks than in everyday code. One of my favorite uses for attributes is when applied to enum values, which can be quite nifty in many cases.