Class Variables

Variables are a 'boxes' to contain information of defined type. 

Creating class variables

To create a class variable press ‘plus’ button on the right side of Class variables section:

Renaming the variable can be done by double clicking on its name.


Variable type

Variable type can be changed by pressing button in Variable type section of details window:


All the most using types placed at the top of type list.

Each variable can have a default value, which will be set initially. For default types the default value will be set automatically (read Default Values Table for more details). For referencing or struct types there can be a constructor for initializing variable with parameters, which can be turned on by using checkbox:

If type has few constructors you can switch between them by pressing right/left arrow buttons.

Main Images: v4.png


Variable modifiers

Access modifiers control the access of variable for other classes and visibility in inspector window.


public - access is not restricted.

protected - access is limited to the containing class or types derived from the containing class.

internal - access is limited to the current assembly.

protected internal - access is limited to the current assembly or types derived from the containing class.

private - access is limited to the containing type.

static modifier is used to declare a static member, which belongs to the type itself rather than to a specific object.

const is used to declare a constant field or a constant local. Constant fields can’t be modified.


Variable Attributes

Attributes can add some functionality to a variable or change the appearance in inspector window. To add attribute to a variable press ‘plus’ button in attribute section and select it from list. Also you can use search field to find the attribute faster.


The most used attributes:

RangeAttribute – change numeric field to a horizontal slider in inspector for a numeric variable;

HideInInspector – don’t display variable in inspector;

SpaceAttribute – add spacing under variable in inspector;

TooltipAttribute – show a tooltipe when mouse on variable in inspector;

SerializeField – allow to change values of private variables in inspector.

Render time: 0.02 seconds
137,010 unique visits