- Home /
How Do I Create A Nested Function With Unity JavaScript?
I am trying to to create a radial menu function with multiple components to it but having some problems.
My Function looks like this and will display a radial menu when the middle mouse button is held down
function RadialMenu ()
{
function Display ()
{
if (Input.GetButton("Activate Radial Menu"))
{
radialMenuBack.enabled = true;
}
else
{
radialMenuBack.enabled = !true;
}
}
function Update ()
{
//code goes here
}
}
This throws compiler errors and won't work... I wasn't sure if I was just being retarded, probably am, so I copied and pasted the following code from here
function person(firstname,lastname,age,eyecolor)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
this.changeName=changeName;
function changeName(name)
{
this.lastname=name;
}
}
This also throws compiler errors, and I'm not sure how to get this working.
Any help with this is appreciated. Thanks!
Unity does not use Javascript, so Javascript code will not work. What's officially called "Javascript" (unfortunately) is actually a custom language called Unityscript, which has little compatibility with Javascript. You'd have much better luck translating ActionScript3 code to Unityscript, since they're very similar in many ways.
Good to know thanks a lot!
I guess I could make some pretty sweet animations using ActionScript3, and hopefully Flash.
Answer by Eric5h5 · Oct 09, 2013 at 05:20 AM
You can't have nested functions. Unity uses a component-based architecture, so simply remove the "function RadialMenu" part, and put the Display and Update functions in a script called RadialMenu, then attach that script to whatever objects you want.
Your answer
Follow this Question
Related Questions
Limit on GUI Components? 0 Answers
How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers
gui rotational issues 0 Answers
play audioclip problem 1 Answer