Introduction

Variable attributes are an essential concept in C# with Unity because they allow us to add extra information or behavior to variables in our scripts. In this lesson, we’ll explore some key variable attributes in C# with Unity and provide examples and illustrations to help us understand how they work. Please note that the fields discussed would be approximately accessible within the Unity Editor interface, as depicted in the screenshots, for context.

The [SerializeField] attribute

The [SerializeField] attribute makes private variables visible in the Unity Inspector. This is useful for editing variables that are not intended to be changed by other scripts but still need to be exposed to the editor.

Here’s an example of the use of the [SerializeField] attribute in C#:

Get hands-on with 1200+ tech skills courses.