I want to use Javascript to create a new class in the Unity.But I don't know how to create it. Could you give me a simple example? Thanks!
class NewClass
{
var classVar1 : int; //example of variable local to class
function NewClass()
{
//init code when instance of class created
}
function classFunction1() // example of function local to class
{
}
}
Defining the class formally as cncguy demonstrates, and putting those class definition files in the Plugins folder allows you to declare variables using them as types in other scripts without having to attach them to an object in the scene and then do GameObject.Find or GetComponent to refer to them. Keep in mind that as type declarations, they can't dynamically find other scripts in their functions with GetComponent except as by string reference (GetComponent("MyOtherScript"), since the Plugin class definition doesn't know about what's in your scene.
For example, if you wanted to use the class described above in another script, you would just say:
var myNewVariable : NewClass = new NewClass();
myNewVariable.classVar1 = 10;
Any UnityScript file that you create basically defines a class that descends from MonoBehavior, but yes, you can define your own types as well. You'll find many examples in the tutorials and the Standard Assets included with Unity.