[DisallowMultipleComponent]
[RequireComponent( typeof( Rigidbody ) )]
public class AttributesExample : MonoBehaviour
{
[...]
}
[DisallowMultipleComponent]
The DisallowMultipleComponent attribute prevents users adding multiple instances of this component to one GameObject.
[RequireComponent( typeof( Rigidbody ) )]
The RequireComponent attribute allows you to specify another component (or more) as requirements for when this component is added to a GameObject. When you add this component to a GameObject, the required components will be automatically added (if not already present) and those components cannot be removed until the one that requires them is removed.