- Home /
function properties in Unity Javascript
Hi, I wanted to explore what can be done with functions in Unity3D javascript. In regular javascript every function is a Function object. What is a function in Unity3D javascript? If I do a Debug.Log(this.Update) this is what I get CompilerGenerated.MyClass_OnMouseDown$callable0$33_38. First thing, why is it printing OnMouseDown instead of Update and, more important, what kind of object is Update and OnMouseDown? Please help! =<
Answer by Peter G · Jul 24, 2011 at 10:50 PM
They're both function types.
var myFunc : function = Update;
then you can pass them to a function:
function SomeAction ( target : Object , callback : function(Object) ) {
callback(target);
}
Answer by YikYikHeiHei · Jul 25, 2011 at 12:33 AM
Are you want to show what is Update?
If that, you should do this
Debug.Log(Function) //<-- It should make Function.
Unity Function can use in a var in javascript.
var callFunction : Function;
function Start ()
{
callFunction = MainMenu;
}
function OnGUI ()
{
callFunction();
}
function MainMenu ()
{
// Do something about main menu
if (GUILayout.Button("Setting"))
{
callFunction = Setting;
}
}
function Setting ()
{
// Do something about setting
if (GUILayout.Button("Main Menu"))
{
callFunction = MainMenu;
}
}
Your answer
Follow this Question
Related Questions
Return multiple parameter 3 Answers
Call GUITexture and script 1 Answer
How to call a function from another script without referencing it? 1 Answer
Variable inside a function's NAME - does it work? 2 Answers
RPC call failed 1 Answer