Attributes in Script

Basics

Attributes is special markers that can be placed above a class, field or method in a script to indicate special for Force behaviour and also for .NET Framework. For example, you can add the ShowInInspector attribute above a field declaration to prevent the Inspector from showing the field, even if it is private.

C# contains attribute names within square brackets, like so:

using Force;

public class AttributesExample : MonoScript {

	[HideInInspector]
	private float speed;
	
	private string velocity;
}

In this case field speed will be displayed in Inspector as if public, and velocity stay private. Also its not change the field access modifier.

Last updated