MenuCommand Manual     Reference     Scripting  
Scripting > Editor Classes > MenuCommand
MenuCommand

Used to extract the context for a MenuItem. MenuCommand objects are passed to custom menu item functions defined using the MenuItem attribute.

Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.

// Add context menu named "Something" to context menu
@MenuItem ("CONTEXT/Rigidbody/Do Something")
static function Something (command : MenuCommand) {
var body : Rigidbody = command.context;
body.mass = 5;
Debug.Log ("Changed Rigidbody's Mass to " + body.mass + " from Context Menu...");
}

See Also: MenuItem

Variables
context

Context is the object that is the target of a menu command.

userData

An integer for passing custom information to a menu item.

Constructors
MenuCommand

Creates a new MenuCommand object.