C# Unity Built-In Attributes (Part 1)
Today I’ll show you some really useful attributes that are built into Unity, which can have some nice effects on your code.
There are some Attributes that can be added before the class definition in order to give the class certain properties or abilities.
There are many such Attributes, but the ones above do the following:
- AddComponentMenu(): Allows you to override where in the Component Menu your script appears.
- RequireComponent(): Forces a component of the type specified to be on the same GameObject as this script.
- Header(): Adds a custom heading to that spot on the Inspector.
- SerializeField: Makes a private variable show up on the Inspector as if it was public, while still being private.
- HideInInspector: As the name suggests, this makes the variable not show up in the Inspector, regardless of its accessibility level.
- Min(): Applied to number variables, it adds a minimum value to the Inspector, not allowing the value to go below this. There is no Max attribute.
- Range(): Similar to Min, but adds both a minimum and a maximum value, while also adding a nice slider to the Inspector.
That’s all for today!
Since there is a lot of info and uses for Attributes in Unity, I will go over more of them in tomorrow’s post. I’ll be making a few posts about this, including how to make your own useful Attributes!